Click here to Skip to main content
15,567,482 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I use the following function to upload files to filezilla.

public static void Upload(string filename)
            FtpWebRequest request = FtpWebRequest)FtpWebRequest.Create("ftp://64.565.210.41" + "/" +
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential("Username", "password");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = false;
            FileStream stream = File.OpenRead(@filename);
            byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            Stream reqStream = request.GetRequestStream();
            reqStream.Write(buffer, 0, buffer.Length);

This works fine for small text files, however when uploading a large video file it cuts of at a certain point and disconnects. Is there an easy way to modify this to allow for larger file sizes.
DaveAuld 26-Oct-10 12:08pm    
You need to understand why it fails, maybe your connection is being terminated, or your adsl link drops etc. if that is the case, there is nothing you can do about it in code. Phone your provider.
Does the transfer stop at exactly the same point every time?
Have you tried to look at any server or client logs?
Neil Cross 27-Oct-10 6:15am    
I managed to get it working. I simply ran the code on a separate thread and it seemed to work. Thanks for commenting.
Sunasara Imdadhusen 18-Nov-10 9:32am    
you should check what is default size and how can you extend the size
BillW33 18-Nov-10 10:36am    
If you figured it out you should post it as an answer then mark is as "answered" so that it doesn't show up on the list of unanswered questions.

1 solution

Apologies for not closing this thread properly. I ended up using the ftplib class found on this site. It works much better for uploading and downloading. Thanks for commenting.
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