首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >FtpWebRequest返回错误550文件不可用

FtpWebRequest返回错误550文件不可用
EN

Stack Overflow用户
提问于 2013-07-04 21:37:26
回答 15查看 101.8K关注 0票数 31

我已经创建了一个小的windows窗体应用程序来上传文件到我们客户的ftp站点之一。但我遇到的问题是,当我在本地机器上运行此应用程序时,它会成功上载文件。但是如果我在我们的服务器上运行这个程序,我得到这个错误信息;

remote服务器在此行'objFTPRequest.GetRequestStream();‘上返回错误:(550)文件不可用(例如,找不到文件,无法访问文件)。

有人知道为什么吗?我需要配置防火墙或其他什么吗?这是我的代码;

代码语言:javascript
复制
FileInfo objFile = new FileInfo(filename);
FtpWebRequest objFTPRequest;

// Create FtpWebRequest object 
objFTPRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/outbox/" + objFile.Name));

// Set Credintials
objFTPRequest.Credentials = new NetworkCredential(ftpUserName, ftpPassword);

// By default KeepAlive is true, where the control connection is 
// not closed after a command is executed.
objFTPRequest.KeepAlive = false;

// Set the data transfer type.
objFTPRequest.UseBinary = true;

// Set content length
objFTPRequest.ContentLength = objFile.Length;

// Set request method
objFTPRequest.Method = WebRequestMethods.Ftp.UploadFile;

// Set buffer size
int intBufferLength = 16 * 1024;
byte[] objBuffer = new byte[intBufferLength];

// Opens a file to read
FileStream objFileStream = objFile.OpenRead();


// Get Stream of the file
Stream objStream = objFTPRequest.GetRequestStream();

int len = 0;

while ((len = objFileStream.Read(objBuffer, 0, intBufferLength)) != 0)
{
    // Write file Content 
    objStream.Write(objBuffer, 0, len);

}

            objStream.Close();
            objFileStream.Close();
EN

回答 15

Stack Overflow用户

发布于 2013-07-04 22:14:19

此错误可能是由于多种原因造成的,如服务器上不存在文件、文件的安全权限等。

首先,您需要找出错误的确切原因。这可以通过使用以下代码来实现-

代码语言:javascript
复制
try
{
        //Your code
}
catch(WebException e)
{
        String status = ((FtpWebResponse)e.Response).StatusDescription;
}

一旦你得到了错误的确切原因,你就可以继续解决它。

这里有一些你可以参考的链接

http://forums.asp.net/t/1777881.aspx/1

http://nickstips.wordpress.com/2010/10/25/c-ftp-upload-error-the-remote-server-returned-an-error-550-file-unavailable-e-g-file-not-found-no-access/

http://www.dreamincode.net/forums/topic/76361-file-upload-to-server/

http://forums.asp.net/t/1374306.aspx/1

票数 38
EN

Stack Overflow用户

发布于 2014-12-15 23:10:55

试试这个:ftp://xxx.xxx.xx.xx:21//path/filename

服务器地址后的"//“从根目录开始。即使我有:ftp://xxx.xxx.xx.xx:21/path/filename,它也没有把我带到正确的目录。

票数 26
EN

Stack Overflow用户

发布于 2013-07-10 01:07:57

我遇到了同样的问题,这就是我所做的:

  1. 检查操作系统是否具有写入权限。找到ftp文件夹=>right click=>properties=>security,然后你必须知道你应该做什么,检查
  2. ftp服务器打开你登录的用户的写权限。打开IIS=>click ftp site=>ftp Authorization Rules=>add allow rules=>choose a user or group to set
  3. 检查ftp服务器上的目录,对项目2执行相同的操作。

我可以用四张图片来显示要设置的权限:

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17471745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档