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.