2

Here is my code.

FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("path");
ftpRequest.Credentials = new NetworkCredential("log", "pass");

ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
byte[] fileContent;  //in this array you'll store the file's content

using (StreamReader sr = new StreamReader(@"pathToFile"))  //'myFile.txt' is the file we want to upload
{
    fileContent = Encoding.UTF8.GetBytes(sr.ReadToEnd()); //getting the file's content, already transformed into a byte array
}

using (Stream sw = ftpRequest.GetRequestStream())
{
    sw.Write(fileContent, 0, fileContent.Length);  //sending the content to the FTP Server
}

.txt files upload correctly with content but .pdf file not. Have no idea where problem is.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Kenik
  • 103
  • 1
  • 15

1 Answers1

1

Why do you want to reinvent the upload file FTP while there is already WebClient implemented by Microsoft?

"STOR" means this is a upload in FTP

using (WebClient client = new WebClient())
{
    client.Credentials = new NetworkCredential("log", "pass");
    client.UploadFile("your_server", "STOR", filePath);
}
Antoine V
  • 6,998
  • 2
  • 11
  • 34