FTPClient download file failed,the retrieveFile() method replyCode=550

五迷三道 提交于 2019-12-05 10:43:51

I found that Apache retrieveFile(...) sometimes did not work with File Sizes exceeding a certain limit. To overcome that I would used retrieveFileStream() instead. Prior to download I have set the Correct FileType and set the Mode to PassiveMode

So the code will look like

    ....
    ftpClientConnection.setFileType(FTP.BINARY_FILE_TYPE);
    ftpClientConnection.enterLocalPassiveMode();
    ftpClientConnection.setAutodetectUTF8(true);

    //Create an InputStream to the File Data and use FileOutputStream to write it
    InputStream inputStream = ftpClientConnection.retrieveFileStream(ftpFile.getName());
    FileOutputStream fileOutputStream = new FileOutputStream(directoryName + "/" + ftpFile.getName());
    //Using org.apache.commons.io.IOUtils
    IOUtils.copy(inputStream, fileOutputStream);
    fileOutputStream.flush();
    IOUtils.closeQuietly(fileOutputStream);
    IOUtils.closeQuietly(inputStream);
    boolean commandOK = ftpClientConnection.completePendingCommand();
    ....

FTP Error 550 Requested action not taken. File unavailable, not found, not accessible

So I think the enconding is a bit wierd, I do not set control encoding and use the retrieveFile just sending a normal String in java. Also this line:

ftpClient.retrieveFile(new String(remoteFileName.getBytes("ms932"),"ISO-8859-1"), fos);

does nothing because you are creating a new Java string from another string. Java strings are kept in memory in a different encoding, compatible with all encodings if I am not mistaken.

Also, the path you are using is wrong, see:

String remoteFileName = "//ftpserver.zip";

Ftp will cause error starting a path with /, try this:

"ftpserver.zip"

or if you have a subdir, try this:

"subdir/myfile.zip"

Cheers

Recently i came across the same error but it was mainly because the path was incorrect and instead of appending a slash as in /data/csms/trt/file.txt it was getting appended as /data/csms/trtfile.txt ...so the file was not being retrieved from the desired location.

setControlEncoding needs to be called before connect, like this

[...]
try {
    ftpClient.setControlEncoding("UTF-8");
    ftpClient.connect("192.168.1.102",2121);
    ftpClient.login("myusername", "12345678");
[...]

Looks like the output path isn't correct. Check the shared root directory on your server. If the root is f:\ and your file is in this root directory, then you only need to do this: `fos = new FileOutputStream("down.zip");

If your file is in a sub-directory of the root, for example, f:\sub, then it should be fos = new FileOutputStream("sub\\down.zip");

I had the same problem, because i had no space in my SDCARD/PHONE Memory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!