Sign in to follow this  

[.net] FTP upload problem! (FtpWebRequest)

Recommended Posts

Hi! I'm trying to upload a ZIP file the following way:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("");
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.UsePassive = true;

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

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();

StreamReader reader = new StreamReader(responseStream);

StreamWriter writer = new StreamWriter("");



I have two problems with it: 1.: if i try to upload more files, i get a "bad sequence of commands" FTP error. 2.: if i upload only this single ZIP file, it gets corrupted (only about the half of the file is actually uploaded without getting any exceptions or other errors. And its even more strange: uploading a 8Mb textfile is 100% okay) Am i missing something in my code? Please help! Thanks in advance! orbano update: always only 156 913 bytes get uploaded onto the server.... :S (this fixed number is the function of the actual filesize)

Share this post

Link to post
Share on other sites
hrmm, I use basically the same code you use there and mine seems to work fine. (I have only used this for text files though).

Just a guess is that if you can upload an 8 mb text file fine, but not a binary file, it seems you have to set a mode to binary somewhere along the line.

When I get done with work here, i'll try uploading some binary files and see if I get the same problem ad you, or if I can find a fix.


Share this post

Link to post
Share on other sites
Make sure to perform the action in binary.

Use a loop to read portions of the file at a time and check the return result of read to make sure that you actually read in all the bytes that you requested.

This will provide examples of just about everything that you might want to do with this class:

Share this post

Link to post
Share on other sites
thanks guys!

somewhy i did not recieve an email notification for your posts... i found out there is a binary mode flag, but setting it to true did not help. i will try to uplad in chunks nad check results. thanks again!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this