Java code to save file on FTP server
import org.apache.commons.net.ftp.FTPClient;
@Override
public void backupToFTP() {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect(host);
client.login(FTPUsername, FTPPassword);
fis = new FileInputStream(filePath);
client.storeFile(newFileName, fis);
client.logout();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void backupToFTP() {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect(host);
client.login(FTPUsername, FTPPassword);
fis = new FileInputStream(filePath);
client.storeFile(newFileName, fis);
client.logout();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}