我正在尝试编写一个片段,以通过FTP通过仅允许https连接的网络下载特定文件(对于其他人,我需要使用特定的代理)。
我要下载的文件:ftp://europabarbarorum.org/EB1.1.exe.torrent
您无需登录即可下载它。
我在哪里做错了?
这是我可以通过Google Chrome(带有代理)成功下载文件的地方:
GENERAL
Request URL: ftp://europabarbarorum.org/EB1.1.exe.torrent
Request Method: GET
Status Code: 200 OK
Remote Address: 10.7.255.29:8080
Referrer Policy: no-referrer-when-downgrade
RESPONSE HEADERS
Age: 11
Connection: keep-alive
Content-Length: 16169
Content-Type: text/plain
Date: Fri, 25 Jan 2019 16:05:50 GMT
Last-Modified: Tue, 13 Jan 2009 07:51:15 GMT
Mime-Version: 1.0
Server: squid/3.5.21
Via: 1.1 ced01squidp02.replynet.prv (squid/3.5.21)
X-Cache: HIT from ced01squidp02.replynet.prv
X-Cache-Lookup: HIT from ced01squidp02.replynet.prv:8080
Resource interpreted as Document but transferred with MIME type application/octet-stream: "ftp://europabarbarorum.org/EB1.1.exe.torrent".
我尝试使用FTPHTTPClient通过代理服务器下载文件,但没有成功。
String url = "ftp://europabarbarorum.org/EB1.1.exe.torrent";
String server = "europabarbarorum.org";
String filePath = "/EB1.1.exe.torrent";
byte[] rtn = null;
boolean success;
int port = 21;
String prox = "proxy.reply.it";
int proxport = 8080;
FTPHTTPClient ftpClient = new FTPHTTPClient(prox, proxport);
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
ftpClient.connect(server);
ftpClient.getReplyCode(); // 220
ftpClient.enterLocalPassiveMode();
ftpClient.getReplyCode(); // 503
ftpClient.setFileType(FTP.BINARY_FILE_TYPE); // false
ftpClient.getReplyCode(); // 503
ftpClient.retrieveFile(filePath, bout); //false
rtn = bout.toByteArray();
} catch (IOException e) {
//no exception caught
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException e) {
//no exception caught
}
}
if(rtn != null)
for (byte b : rtn)
System.out.print(b+" "); // nothing here