FTP,的GetResponse(),错误550文件不可用不可用、错误、文件、FTP

由网友(情話再甜乜只是敷衍)分享简介:我创建了一个小的Windows窗体应用程序将文件上传到我们的客户的ftp站点之一。但是,我遇到的问题是,当我在我的本地计算机上运行该应用程序成功地上传文件。但是,如果我在我们的服务器上运行这个程序,我得到这个错误信息; 远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件),在这条线objFT pr...

我创建了一个小的Windows窗体应用程序将文件上传到我们的客户的ftp站点之一。但是,我遇到的问题是,当我在我的本地计算机上运行该应用程序成功地上传文件。但是,如果我在我们的服务器上运行这个程序,我得到这个错误信息;

  

远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件),在这条线objFT prequest.GetRequestStream();

有谁知道为什么吗?我是否需要配置防火墙什么的?这是我的code;

  FileInfo的OBJFILE =新的FileInfo(文件名);
的FtpWebRequest objFT prequest;

//创建的FtpWebRequest对象
objFT prequest =(的FtpWebRequest)FtpWebRequest.Create(新的URI(FTP://+ ftpServerIP +/件箱/+ objFile.Name));

//设置Credintials
objFT prequest.Credentials =新的NetworkCredential(ftpUserName,ftpPassword);

//默认的KeepAlive是真实的,其中控制连接是
在执行命令后//没有关闭。
objFT prequest.KeepAlive = FALSE;

//设置数据传输的类型。
objFT prequest.UseBinary = TRUE;

//设置内容长度
objFT prequest.ContentLength = objFile.Length;

//设置请求方法
objFT prequest.Method = WebRequestMethods.Ftp.UploadFile;

//设置缓冲区大小
INT intBufferLength = 16 * 1024;
byte []的objBuffer =新的字节[intBufferLength]

//打开一个文件的读取
的FileStream objFileStream = objFile.OpenRead();


//获取文件的流
流objStream = objFT prequest.GetRequestStream();

INT的len = 0;

而((LEN = objFileStream.Read(objBuffer,0,intBufferLength))!= 0)
{
    //写文件内容
    objStream.Write(objBuffer,0,的len);

}

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

解决方案

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

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

 尝试
{
        //你的code
}
赶上(WebException E)
{
        字符串状态=((FtpWebResponse)e.Response).StatusDescription;
}
 
win8搭建FTP问题

一旦你得到错误的确切原因,你可以去期待解决这个问题。

下面是一些链接,您可以参考

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

http://nickstips.word$p$pss.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.dreamin$c$c.net/forums/topic/76361-file-upload-to-server/

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

I have created a small windows forms application to upload the file to one of our client's ftp site. But the problem that I'm having is that when I run this application on my local machine it uploads the file successfully. But if I run this program on our server, I get this error message;

remote server returned an error: (550) File unavailable (eg, file not found, can not access the file), on this line 'objFTPRequest.GetRequestStream();'.

Does anybody know why? Do I need to configure the firewall or something? Here is my code;

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();

解决方案

This error can be caused because of several reasons like file is not present on server, security permissions on file etc. etc.

First you need to find out the exact cause of error. This can be achieved by using following code-

try
{
        //Your code
}
catch(WebException e)
{
        String status = ((FtpWebResponse)e.Response).StatusDescription;
}

Once you get the exact cause of error, you can go forward to solve it.

Here are some links you can refer

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

阅读全文

相关推荐

最新文章