FTP, GetResponse (), error 550 File unavailable

2019-01-09 11:41发布

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

13条回答
我命由我不由天
2楼-- · 2019-01-09 12:36

I met the same problem, and this is what I did:

  1. Check the OS has the right to write. Find the ftp folder =>right click=>properties=>security, then you must know what you should do
  2. Check the ftp server open the write right to the user you logged. Open IIS=>click the ftp site=>ftp Authorization Rules=>add allow rules=>choose a user or group to set the rights
  3. Check the the dir on the ftp server, do the same thing on item 2.

I can use four pictures to show the rights to be set: enter image description here

enter image description here enter image description here enter image description here

查看更多
聊天终结者
3楼-- · 2019-01-09 12:38

I had this problem. Filezilla was fine, .net wasn't. It was to a wordpress server. To get it working, I changed the my code from this:

ftp://XXX.XXX.XXX.XXX//folder//" + txtFile.Text

to:

ftp://[FTPNAME]@XXX.XXX.XXX.XXX//" + txtFile.Text

and it now thankfully works.

I don't know if this is specific to Wordpress FTP folders.

查看更多
萌系小妹纸
4楼-- · 2019-01-09 12:39

It could be more simple.

I facing similar issue and i tried all the suggested solution but no one work. I'm figure out in simple manner like this one : take a look

Wrong code at my end

 Dim request As Net.FtpWebRequest = CType(FtpWebRequest.Create("ftp://xxx.xxx.xxx.xxx/files"), FtpWebRequest)

Change it in this simple one :

 Dim request As Net.FtpWebRequest = CType(FtpWebRequest.Create("ftp://xxx.xxx.xxx.xxx/files/youfilename.ext"), FtpWebRequest)

then procced with fill request and send to server :)

That's all.

Make sure that all permission on server work fine and u're using right credential.

查看更多
SAY GOODBYE
5楼-- · 2019-01-09 12:39

When i had the same issue i tried everything above and after a day later i realize that the path which i created for uri having a white space in between "/" and the folder name

string uri="192.168.1.101/ Sync/Image.jpg";

the above string should be

string uri="192.168.1.101/Sync/Image.jpg";

this small mistake also throws the same error and it's a valid error because this is not valid path for our file if it contains any white spaces between "/" and folder/file name

查看更多
做个烂人
6楼-- · 2019-01-09 12:40

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

查看更多
别忘想泡老子
7楼-- · 2019-01-09 12:41

Try this: ftp://xxx.xxx.xx.xx:21//path/filename

The "//" after the server address starts you out at the root directory. Even though I had: ftp://xxx.xxx.xx.xx:21/path/filename, it didn't take me to the correct directory.

查看更多
登录 后发表回答