import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class FTPUploader {
public static void main(String[] args) {
String server = "ftp.example.com";
int port = 21;
String username = "username";
String password = "password";
String localFilePath = "/path/to/local/file.txt";
String remoteFilePath = "/path/to/remote/file.txt";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(server, port);
ftpClient.login(username, password);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
File localFile = new File(localFilePath);
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(localFile));
ftpClient.storeFile(remoteFilePath, inputStream);
inputStream.close();
ftpClient.logout();
ftpClient.disconnect();
System.out.println("File uploaded successfully.");
} catch (IOException e) {
e.printStackTrace();
}
}
}