Click here to Skip to main content
15,884,962 members
Articles / General Programming / Internet
Tip/Trick

Easy FTP Upload without files size limit

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
18 Oct 2011CPOL 35K   11   1
Easy FTP Upload without files size limit
The typical way and examples for send(Upload) a file to FTP server uses slow requests and the FileStream class that imposes restrictions in the size of files that are uploaded.

I present my short and easy way to upload a file to FTP server without file size limits:

C#
using System.Net;

            // Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://
            XXXXXXXXXXXXXXXXXXXXX/" + "C:/XXXXX.zip");
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential("User", "PassWord");

            // Copy the contents of the file to the request stream.
            Stream ftpStream = request.GetRequestStream();
            FileStream file = File.OpenRead("C:/XXXXX.zip");

            int length = 1024;
            byte[] buffer = new byte[length];
            int bytesread = 0;

            do
            {
            bytesread = file.Read(buffer,0,length);
            ftpStream.Write(buffer,0,bytesread);
            }
            while(bytesread != 0);

            file.Close();
            ftpStream.Close();

            MessageBox.Show("Uploaded Successfully");


I hope that helps you...:)

Regards,
Sergio Andrés Gutiérrez Rojas

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Learn Production AI
Colombia Colombia
MSc. Artificial intelligence
Systems engineer
Senior software developer
Networks technologist
Artificial vision, AI and robotic lover
Technology enthusiast
Gamer

Learn Production AI founder
Motion Soft Co-founder
MIA PC Friend Developer

Take practical professional artificial vision courses (desktop and mobile) in Learn Production AI: https://www.learnproductionai.tech

Comments and Discussions

 
QuestionEasy FTP Upload without files size limit Pin
Member 145932597-Dec-20 23:45
Member 145932597-Dec-20 23:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.