轉自:
http://www.java265.com/JavaJingYan/202205/16526275913390.html
實作思路:
使用Apache Commons中FTPClient類
即可實作上傳檔案至FTP伺服器的方法
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
//輸入FTP伺服器資訊
client.connect("ftp.java265.com");
client.login("admin", "secret");
//
// 待上傳檔案
//
String filename = "Test.txt";
fis = new FileInputStream(filename);
//
// 存儲檔案至FTP伺服器中
//
client.storeFile(filename, fis);
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}