Upload file to AS400 using FtpWebRequest

Answered Upload file to AS400 using FtpWebRequest

  • Saturday, September 01, 2012 12:18 PM
     
     

    I’m attempting to upload a file to AS400 using C#. The structure is:  ftp server ip address/library/table. E.g. 10.123.1.23/ABCD/XYZ. FileName : sample.txt

    The AS400 table has same fields as my file layout. I am able to successfully upload file using ftp commands using PUT command as below.

    ftp> open 10.123.1.23

    ftp> username

    ftp> password

    ftp> cd ABCD

    ftp> put sample.txt ABCD/XYZ. I get a success message.

    But when I try using FtpWebRequest, i get a 550 :” File unavailable or no access” error message.’

    I’m not sure how to construct the URI. Currently, my code looks like

    FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(@"ftp://110.123.1.23/ABCD/” + file.Name);

     

    Also, i’m unable to browse to the ftp folder using internet explorer or windows explorer. I get the same 550 error.

    i'm using .Net 4.0, VS 2010

    Any help is much appreciated.

All Replies

  • Saturday, September 01, 2012 2:15 PM
     
     Answered
    The file on the server should not be specified in the .Create() call, as it does not yet exist.   See the example here: http://msdn.microsoft.com/en-us/library/ms229715.aspx
     

    --
    Mike
    • Marked As Answer by D2012 Saturday, September 01, 2012 4:31 PM
    •  
  • Saturday, September 01, 2012 4:28 PM
     
     

    @Mike Thanks a ton. That worked. Modified URL looks like this

    FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(@"ftp://110.123.1.23/ABCD/XYZ);

    • Edited by D2012 Saturday, September 01, 2012 4:33 PM
    •