Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I tried to ftp upload a text file to AS400 and it keeps giving me error "The remote server returned an error: (501) Syntax error in parameters or arguments." I am not sure which parameter is wrong. It throws error at miRequest.GetRequestStream(). Any help will be greatly appreciated.



Here is my code
VB
Dim miUri As New Uri("ftp://hostIpAddress/LIBname/filename")
        Dim mirequest As FtpWebRequest
        mirequest = DirectCast(Net.WebRequest.Create(miUri), FtpWebRequest)
        miRequest.Credentials = New Net.NetworkCredential(user, password)
        miRequest.KeepAlive = False
        miRequest.UseBinary = False
        miRequest.UsePassive = True
        miRequest.ContentLength = FileLen("C:\test.txt")

        miRequest.Method = Net.WebRequestMethods.Ftp.UploadFile

        Try
            Dim miStream As System.IO.Stream
            miStream = miRequest.GetRequestStream()
            Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\test.txt")
            miStream.Write(bFile, 0, bFile.Length)
            miStream.Close()
            miStream.Dispose()
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
Posted
Updated 16-Jul-13 16:23pm
v2

See http://support.microsoft.com/kb/2134299/en-us[^]: the behavior of the ftp request changed between .Net 3.5 and .Net 4, which causes problems in "non-fully RFC compliant servers". The information on the Microsoft page shows you a workaround (actually more of a hack: change a non-public property of the FtpWebRequest class by reflection) to circumvent that problem.
 
Share this answer
 
Comments
snoopy18 17-Jul-13 15:27pm    
I will take a look but my PC only has .Net 3.5 installed.
the uri has to be special format ftp://hostip/%2F/QSYS.LIB/libname.LIB/filename.FILE
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900