I write a piece of code just for testing to send txt file with type ASCII to FTP server, but keep getting following error.
The remote server returned an error: (501) Syntax error in parameters or arguments.
I am sure the user name and password is correct, and I tried to set UsePassive true and false but get same error.
The following is the code I used.
Imports System.IO
Imports System.Text
Imports System.Net
Module Module1
Sub Main()
Dim lPOSByteArray() As Byte
Dim lEncoding As New ASCIIEncoding
Dim lPOSFlatFile As String
lPOSFlatFile = System.IO.File.ReadAllText("C:\\Users\\somebody\\Desktop\\Test.config.XML")
lPOSByteArray = lEncoding.GetBytes(lPOSFlatFile)
Dim lFTPrequest As System.Net.FtpWebRequest
lFTPrequest = DirectCast(WebRequest.Create("ftp://" & "199.222.111.111" & "/" & "Test.txt"), System.Net.FtpWebRequest)
lFTPrequest.Proxy = Nothing
lFTPrequest.Credentials = New NetworkCredential("userxxx", "passyyy")
lFTPrequest.Method = WebRequestMethods.Ftp.UploadFile
lFTPrequest.UseBinary = False
lFTPrequest.UsePassive = True
lFTPrequest.ContentLength = lPOSByteArray.Length
'ERROR happened on following line
Dim lFTPrequestStream As Stream = lFTPrequest.GetRequestStream()
lFTPrequestStream.Write(lPOSByteArray, 0, lPOSByteArray.Length)
lFTPrequestStream.Close()
Dim response As System.Net.FtpWebResponse = DirectCast(lFTPrequest.GetResponse(), System.Net.FtpWebResponse)
End Sub
End Module
I think that your code is right. The problem is in another place, like network or ftp server. I tried with my FTP server and changed the line
to
and works fine. Can you read/write this file with a ftp client like FileZila?