Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 6th, 2006, 06:33 PM
Registered User
 
Join Date: Dec 2006
Location: Green Bay, WI, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Uploading Text File to FTP server in vb.net


Hi folks,

I am trying to upload a text file to a FTP server using VB.net Windows’s application.

I used the following code:

        Imports System.IO
        Imports System.Net
        Imports System.Text

        Dim localFile As String = "C:\Yserver.txt"
        Dim remoteFile As String = "ftp://ftpSERVER/test12345.txt"
        Dim username As String = "user"
        Dim password As String = "pwd"

        Dim sourceStream As New StreamReader(localFile)
        Dim fileContents As Byte() = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
        sourceStream.Close()

        'Get the object used to communicate with the server.
        Dim Request As System.Net.FtpWebRequest = FtpWebRequest.Create(remoteFile)

        ' Setting Properties
        Request.Credentials = New NetworkCredential(username, password)
        Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
        Request.Proxy = Nothing
        Request.KeepAlive = False

        ' Uploading file
        Request.GetRequestStream.Write(fileContents, 0, fileContents.Length)
        MsgBox("File Uploaded Successfully !!!")

When I execute these, I am getting following error

System.Net.WebException was caught
Message="The remote server returned an error: (501) Syntax error in parameters or arguments."

Please help me to overcome this.


Reply With Quote
  #2 (permalink)  
Old December 7th, 2006, 11:12 AM
Registered User
 
Join Date: Dec 2006
Location: Green Bay, WI, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Moreover i m trying to connect to AS400 server , No SSL ,No proxy server..

Looking forward for ur Answer !!!
Reply With Quote
  #3 (permalink)  
Old December 13th, 2006, 06:19 AM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will look into this for you later Wednesday.

What is in YServer.txt? Is it really a text file? If it's small enough please post the contents.

Reply With Quote
  #4 (permalink)  
Old July 27th, 2014, 06:16 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In response to your question above. It does not matter what the contents of a file are. There is an error in the conection. check all the login details are correct for the FTP host.

Also if your uploading a file or any sort you need to make sure the file name and type are the same as the designated line of code.

example code to catch errors;

try
code to conect
code to attempt upload
code to close conection
catch ex exception
msgbox("Didnt work!")
code to close connection - disregard and try again
end try

(code may be wrong as im lazy and use memory only)
Reply With Quote
  #5 (permalink)  
Old July 29th, 2014, 03:02 AM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

The exception states what is wrong, it is a 501, this typically means that the server receiving the message had an issue processing your request. Are you sure the server you are connecting to can understand ftp via http. Ftp is a protocol and the server you are sending the web request to must be able to understand it. It is also standard practice to send vague cryptic message when internal errors arise so in my opinion the best way to determine what the exception is, is to have the ftp server owner review logs to determine the root cause.

Last edited by mmorgan30; July 29th, 2014 at 03:08 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ftp text file from excel worksheet zone Excel VBA 0 July 31st, 2007 06:07 PM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 07:53 AM
Save PDF file as text file in VB.Net kvenkatu Classic ASP Basics 0 April 7th, 2006 02:09 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 01:15 PM
file transfer ftp server to a pocket PC in C# .NET g_hristodol ADO.NET 0 October 21st, 2004 07:14 AM



All times are GMT -4. The time now is 01:19 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.