问题描述
朋友们,
我正在使用以下代码并收到错误消息:远程服务器返回错误:(550)文件不可用(例如,找不到文件,无法访问)".请告诉我如何解决此问题.
私人void上传(字符串文件名)
{
FileInfo fil =新的FileInfo(文件名);
FtpWebRequest requestFTPUploader =(FtpWebRequest)WebRequest.Create(FtpServerName +"/" + FtpFilePath +"/" + fil.Name);
requestFTPUploader.Credentials =新的NetworkCredential(FtpUserId,FtpPassword);
requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile;
ServicePoint LServicePoint = requestFTPUploader.ServicePoint;
LServicePoint.ConnectionLimit = 1;
requestFTPUploader.Proxy = new WebProxy(){UseDefaultCredentials = true};
FileInfo fileInfo =新的FileInfo(文件名);
FileStream fileStream = fileInfo.OpenRead();
int bufferLength = 2048;
byte []缓冲区=新的byte [bufferLength];
流uploadStream = requestFTPUploader.GetRequestStream();
int contentLength = fileStream.Read(buffer,0,bufferLength);
while(contentLength!= 0)
{
uploadStream.Write(buffer,0,contentLength);
contentLength = fileStream.Read(buffer,0,bufferLength);
}
uploadStream.Close();
fileStream.Close();
requestFTPUploader = null;
}
Hi frds,
I m using the below code and getting error "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)". Please tell me how to resolve this problem.
private void Upload(string filename)
{
FileInfo fil = new FileInfo(filename);
FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create(FtpServerName+"/"+FtpFilePath+"/" + fil.Name);
requestFTPUploader.Credentials = new NetworkCredential(FtpUserId, FtpPassword);
requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile;
ServicePoint LServicePoint = requestFTPUploader.ServicePoint;
LServicePoint.ConnectionLimit = 1;
requestFTPUploader.Proxy = new WebProxy() { UseDefaultCredentials = true };
FileInfo fileInfo = new FileInfo(filename);
FileStream fileStream = fileInfo.OpenRead();
int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
Stream uploadStream = requestFTPUploader.GetRequestStream();
int contentLength = fileStream.Read(buffer, 0, bufferLength);
while (contentLength != 0)
{
uploadStream.Write(buffer, 0, contentLength);
contentLength = fileStream.Read(buffer, 0, bufferLength);
}
uploadStream.Close();
fileStream.Close();
requestFTPUploader = null;
}
推荐答案
这篇关于将文本文件上传到FTP服务器时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!