Hello. I use the Commons Net 3.4 library from Apache in my application and ran into the following problem. When you try to connect to an FTP server, you get the error: "java.io.IOException: Connection is not open". Can someone help with this problem? Data from FTP entered 100% correct.

public static Boolean downloadAndSaveFile(String server, int portNumber, String user, String password, String filename, File localFile) throws IOException { FTPClient ftp = null; try { ftp = new FTPClient(); ftp.connect(server, portNumber); ftp.login(user, password); ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); OutputStream outputStream = null; boolean success = false; try { outputStream = new BufferedOutputStream(new FileOutputStream(localFile)); success = ftp.retrieveFile(filename, outputStream); } finally { if (outputStream != null) { outputStream.close(); } } return success; } finally { if (ftp != null) { ftp.logout(); ftp.disconnect(); } } } 
  • Permission in the manifest are present? do this in the background? - ermak0ff
  • @ ermak0ff registered android.permission.INTERNET - ahgpoug
  • iii? What is the result? - ermak0ff
  • @ ermak0ff the result is that through the FTP manager connects, and through the application - no - ahgpoug
  • one
    Well, and make this performance in the background - ermak0ff

1 answer 1

The reason for this error can be:

  • lack of permission in the manifest;
  • executing the method in a UI flow.

Respectively solved:

  • adding android.permission.INTERNET ;
  • running the method in the бэкграунде .