将文本文件上传到FTP服务器时出现问题

将文本文件上传到FTP服务器时出现问题

问题描述:

朋友们,

我正在使用以下代码并收到错误消息:远程服务器返回错误:(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;

}

1)您确定webRequest字符串中没有多余的空格吗?
2)检查以确保您具有写入该服务器的正确特权.
1) Are you sure there is no extra white space in the webRequest string?
2) check to make sure you have the correct privileges to write to that server.