FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.revco.hu/update.zip");
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("update.zip");
writer.Write(reader.ReadToEnd());
reader.Close();
writer.Close();
response.Close();
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)
[.net] FTP upload problem! (FtpWebRequest)
Hi! I'm trying to upload a ZIP file the following way:
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.
ArchG
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.
ArchG
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:
http://msdn2.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
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:
http://msdn2.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement