views:

20

answers:

1

Hi, I am trying to upload a file via ftp using FtpWebRequest as below:

ftpRequest = (FtpWebRequest)WebRequest.Create("ftp.somethong.com");

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

ftpRequest.Credentials = new NetworkCredential("user", "pass");

However, when connected and uploaded the file goes into the root, whereas, I need for it to be put into the /Upload directory.

I can make directories but how can I browse there, before uploading the file?

+1  A: 

You'll need to put the directory in the URL you used to create the request, i.e.

 ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://ftp.somethong.com/Upload/filename.ext");
Mark
When trying your suggestion: ftpRequest = (FtpWebRequest)WebRequest.Create("ftp.adftest.rightmove.com/test/upload/test.zip");Invalid URI: The format of the URI could not be determined.And then when trying: ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://adftest.rightmove.com/test/upload/test.zip");Unable to connect to remote server
N00b
^^ not to clear. Essentially, with your suggestion I get Invalid URI: The format of the URI could not be determined. When trying .Create("ftp://adftest.rightmove.com/test/upload/test.zip"); I get Unable to connect to remote server.
N00b
Right, sorry, the URI needs a scheme (ftp://).
Mark
As above I get unable to connect to remote server, maybe some permissions on the ftp server but the method should work. In the end I used: http://www.codeproject.com/KB/IP/ftplib.aspx
N00b