How to upload file using C#

Welcome to InspiringWorm. Follow this step to upload the file using C#.

Create an FTP request

FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + “/” + Path.GetFileName(filePath));

request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = false;
request.UseBinary = true;
request.KeepAlive = false;

Step 2:  load the file

FileStream stream = File.OpenRead(filePath);
byte[] buffer = new byte[stream.Length];

stream.Read(buffer, 0, buffer.Length);

Step 3: Upload the file

Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
kishor bhatta

Hello! I am Kishor Bhatta, a Professional Blogger, and Digital Marketing Strategist. I am the founder of InspiringWorm.

Leave a Comment