步驟 代碼示例
添加依賴(lài) Maven依??賴(lài):commonsnetcommonsnet3.8.0
初始化(hua)FTPClient ftpClient = new FTPClient();
連接FTP服務(wù)器ftpClient.conne┐(′д`)┌ct("ftp.ex??ample.com"??, 21);
登錄ftpClient.login("username", "password");
讀取目錄
下載文件try (OutputStream outputStream = new FileOutputStream(new File("localfile"))) { ftpClient.retrieveFile("remotefile", outputSt??ream); }
上傳文件try (InputStream inputStream = new FileInputStream(new File("localfile"))) { ftpClient.storeFile("remotefile", inputStream); }
斷開(kāi)連接ftpClient.logo??ut(); ftpClient.disconnect();