implementation 'commons-net:commons-net:3.8.0'
上傳/下載核心代碼:
FTPClient ftp = new FTPClient();
ftp.connect(host, port);
ftp.login(user, pass);
ftp.enterLocalPassiveMode();
ftp.setFileType(FTP.BINARY_FILE_TYPE);
// 上傳
ftp.storeFile(remotePath, new FileInputStream(localFile));
// 下載
ftp.retrieveFile(remotePath, new FileOutputStream(localFile));
ftp.logout(); ftp.disconnect();
implementation 'com.github.tony19:simple-ftp:1.0.0'
android:usesCleartextTraffic="true" 或使用 HTTPS/FTPS。ftp.setControlEncoding("UTF-8")。INTERNET、READ_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE(視存儲位置)。