/** Function append smth to remote text file. */ public void appendFile(String fileName, String appendContent) throws SocketException, IOException { connect2Server(); ByteArrayInputStream oInStream = new ByteArrayInputStream((appendContent + "\n").getBytes()); if (!oFtp.appendFile(fileName, oInStream)) { logError( "File `" + fileName + "` can't append. FTP reply code: " + oFtp.getReplyCode() + " Ftp message: " + Arrays.asList(oFtp.getReplyStrings())); } closeFtpConnection(); }
public static void append( String server, String username, String password, String remotePath, InputStream is) throws IOException { FTPClient mFtp = new FTPClient(); try { mFtp.connect(server, FTP.DEFAULT_PORT); mFtp.login(username, password); mFtp.setFileType(FTP.BINARY_FILE_TYPE); mFtp.enterLocalPassiveMode(); mFtp.appendFile(remotePath, is); } finally { try { if (mFtp.isConnected()) { mFtp.logout(); mFtp.disconnect(); } } catch (IOException ex) { ex.printStackTrace(); } } }