将文本文件上传到FTP服务器时出现问题 [英] Problem in Uploading a text file into FTP Server

查看:132
本文介绍了将文本文件上传到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.


这篇关于将文本文件上传到FTP服务器时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆