Welcome to InspiringWorm. Follow this step to upload the file using C#.
Create an FTP request
Table of Contents
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); stream.Close();
Step 3: Upload the file
Stream reqStream = request.GetRequestStream(); reqStream.Write(buffer, 0, buffer.Length); reqStream.Close();
Hello! I am Kishor Bhatta, a Professional Blogger, and Digital Marketing Strategist. I am the founder of InspiringWorm.