Fahim Akhtar

Fahim Akhtar

  • NA
  • 184
  • 8.2k

C#: FTP Upload Error – The remote server returned an error:

Jul 26 2019 4:21 AM
this error show when i upload image file in ftp server.
at this time i want to create a folder or directory and then save picture in this folder.
 
var uploadfilename = "DrivingLicenceCardBack";
Stream streamObj = pic2.InputStream;
byte[] buffer = new byte[pic2.ContentLength];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
string ftpurl = String.Format("{0}/{1}", ftpfullpath, uploadfilename);
var requestObj = FtpWebRequest.Create(ftpurl) as FtpWebRequest;
requestObj.Method = WebRequestMethods.Ftp.UploadFile;
requestObj.Credentials = new NetworkCredential(username, password);
Stream requestStream = requestObj.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestStream.Close();
requestObj = null;

Answers (1)