Failed to load FTPClient file, retrieveFile () method replyCode = 550

/ * I start the FTP server on localhost.when I upload files using the ftpClient.retrieveFile () method, it responds with Code 550. I read the commons-net API and found 550 replyCode, defines "public static final int FILE_UNAVAILABLE 550". But I can not find the problem from my codes.
thank you 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); } } 
+4
source share
6 answers

I found that Apache retrieveFile (...) sometimes did not work with file sizes exceeding a certain limit. To overcome this, I would use retrieveFileStream (). Before downloading, I installed Correct FileType and set 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(); .... 
+7
source

FTP Error 550 The requested actions are not accepted. File not available, not found, not available

So, I think the identification is a little strange, I do not set the control encoding and use retrieveFile, just sending a regular string to 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 stored in memory in a different encoding, compatible with all encodings, if I'm not mistaken.

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

 String remoteFileName = "//ftpserver.zip"; 

Ftp will throw an error starting the path with /, try the following:

 "ftpserver.zip" 

or if you have a subdir, try the following:

 "subdir/myfile.zip" 

Greetings

+2
source

I recently encountered the same error, but this was mainly because the path was wrong and instead of adding a slash, as in /data/csms/trt/file.txt, it was added as / data / csms / trtfile .txt ... therefore the file is not extracted from the required location.

0
source

setControlEncoding needs to be called before connection, for example

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

It seems that the output path is wrong. Check the shared root directory on your server. If the root is f: \ and your file is in this root directory, you only need to do this: `fos = new FileOutputStream (" down.zip ");

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

0
source

I had the same problem because I did not have a place in the SDCARD / PHONE memory.

0
source

All Articles