我正在尝试FTPSClient使用在 Android 模拟器中运行的Java 从本地 FileZilla 服务器下载文件。
我写了这个帮助代码来下载一个文件:
public boolean downloadSingleFile(FTPSClient ftpClient,
String remoteFilePath, File downloadFile) {
OutputStream outputStream;
Log.i("t1", remoteFilePath + " - " + downloadFile.getAbsolutePath());
try {
outputStream = new BufferedOutputStream(new FileOutputStream(
downloadFile));
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
boolean retval = ftpClient.retrieveFile(remoteFilePath, outputStream);
outputStream.flush();
return retval;
} catch (Exception e) {
Log.e("dwFile", e.toString());
Log.e("dwFile", ftpClient.getReplyString());
} return false;
}
我这样称呼这个函数:
FTPSClient dwClient = new FTPSClient();
dwClient.addProtocolCommandListener(
new PrintCommandListener(
new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")), true));
dwClient.setConnectTimeout(30 * 1000);
dwClient.connect(OmsSettingsFunctions.getFTPServer());
Log.i("dwDB", dwClient.getReplyString());
if (dwClient.login(FPTuser, FTPpass)) {
Log.i("dwDB", dwClient.getReplyString());
dwClient.enterLocalPassiveMode();
File dwFile = new File(externalPath + "/Android/data/com.myapp/files/Documents/db.temp");
if(!downloadSingleFile(dwClient, "/DBs/db.txt", dwFile)) {
Log.e("dwDB", "Download could not finish (DB)");
Log.e("dwDB", dwClient.getReplyString());
}...
我已经尝试使用enterLocalActivemode()而不是,enterLocalPassivmode()但它没有帮助。FTP 服务器在我的本地机器上执行和运行 TLS。我通过 10.0.2.2(Android 环回)连接到它。我怎样才能解决这个问题?
慕姐8265434
相关分类