Така че се опитвам да кача файл на моя ftp сървър. Всички неща изглежда работят според очакванията, но когато отворя файла от ftp, получавам I/O грешка. Локалният файл работи добре. Някои начини, по които файлът се поврежда след качване. Открих подобен проблем тук.
Тук прочетох, че трябва да промените режима на прехвърляне на двоичен. Опитах се да задам ftpRequest.UseBinary = true;
, но все още получавам I/O грешка. Трябва ли да променя някъде режима на прехвърляне?
Това е моят код за качване на ftp:
public string upload(string remoteFile, string localFile)
{
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
ftpRequest.UseBinary = true;
ftpRequest.Credentials = new NetworkCredential(user, pass);
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(localFile);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
ftpRequest.ContentLength = fileContents.Length;
Stream requestStream = ftpRequest.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
response.Close();
return string.Format("Upload File Complete, status {0}", response.StatusDescription);
}
Използвайки уебклиент, получавам грешката:
Отдалеченият сървър върна грешка: (553) Името на файл не е разрешено.
Ето моят код:
private void uploadToPDF(int fileName, string localFilePath, string ftpPath, string baseAddress)
{
WebClient webclient = new WebClient();
webclient.BaseAddress = baseAddress;
webclient.Credentials = new NetworkCredential(username, password);
webclient.UploadFile(ftpPath + fileName + ".pdf", localFilePath);
}
ftpPath + fileName + ".pdf"
? - person mkl   schedule 31.10.2013ftp://
пред това? UploadFile очаква URI. - person mkl   schedule 01.11.2013