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