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

6

5

/* I run a FTP server on localhost.when I download files use ftpClient.retrieveFile() method,it's replyCode is 550 . I read the API of commons-net and find the 550 replyCode,the defines is" public static final int FILE_UNAVAILABLE 550".but I cannot find the problem from my codes.
thanks for your help.

*/

    FTPClient ftpClient = new FTPClient();
    FileOutputStream fos = null;

    try {
        ftpClient.connect("192.168.1.102",2121);
        ftpClient.login("myusername", "12345678");
        ftpClient.setControlEncoding("UTF-8");
        ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
        String remoteFileName = "ftpserver.zip";//this file in the rootdir
        fos = new FileOutputStream("f:/down.zip");
        ftpClient.setBufferSize(1024);
        ftpClient.enterLocalPassiveMode();
        ftpClient.enterLocalActiveMode();
        ftpClient.retrieveFile(remoteFileName, fos);  
        System.out.println("retrieveFile?"+ftpClient.getReplyCode());
        fos.close();
        ftpClient.logout();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            ftpClient.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("关闭FTP异常", e);
        }
    }
Install answered 26/9, 2011 at 17:18 Comment(2)
thanks fredcrs. I have changed the remoteFileName and the params of retrieveFile() method but it still dosn't workInstall
On the other hand,I Thought if some problem about my FTP Server.So I want to access the website ftp server.but I haven't a free&available informationInstall
K
12

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();
    ....
Koph answered 15/5, 2013 at 12:53 Comment(3)
From reading the documentation it looks like setAutodetectUTF8 has to be called before connect or it does nothing. I'm not certain what it would for be in binary transfer mode anyway?Harshman
Thanks so much, working on this bugs and trying so much tricks and it was finally the file type ! ThanksDiscriminative
Not works, the retrieveFileStream return null anywayMispickel
P
2

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

Plicate answered 26/9, 2011 at 18:31 Comment(1)
I made the following change and it worked. (without "/home/hadoop") before String remote = "/home/hadoop/remote.txt"; after String remote = "remote.txt";Kamseen
B
1

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.

Balsa answered 16/4, 2012 at 10:4 Comment(0)
M
0

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");
[...]
Mellissamellitz answered 8/2, 2013 at 16:46 Comment(0)
M
0

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

Munch answered 4/11, 2013 at 22:46 Comment(0)
L
0

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

Lowspirited answered 24/1, 2016 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.