我们的网络团队只允许我们通过代理服务器连接到我们的第三方客户端。
有没有办法将代理服务器添加到 apache commons net 的 FTPS 客户端?
如果不可能,你能告诉一个方法如何做到这一点。
顺便说一下,这是在公司网络之外工作的代码
String server = "ftp.xxxx.com";
String username = "username";
String password = "password";
String remoteFile = "xmlSR.xml";
String localFile = "c:/downloadedfile.xml";
String protocol = "TLS"; // TLS / SSL
int timeoutInMillis = 3000;
boolean isImpicit = false;
FTPSClient client = new FTPSClient(protocol, isImpicit);
client.enterLocalActiveMode();
client.setRemoteVerificationEnabled(false);
client.setActivePortRange(50000, 50200);
client.setDataTimeout(timeoutInMillis);
client.addProtocolCommandListener(new PrintCommandListener(
new PrintWriter(System.out)));
client.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
try {
int reply;
client.connect(server);
client.login(username, password);
client.setFileType(FTP.BINARY_FILE_TYPE);
client.execPBSZ(0);
client.execPROT("P");
System.out.println("Connected to " + server + ".");
reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
client.listFiles();
boolean retrieved = client.retrieveFile(remoteFile,
new FileOutputStream(localFile));
} catch (Exception e) {
if (client.isConnected()) {
try {
client.disconnect();
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
return;
} finally {
System.out.println("# client disconnected");
client.disconnect();
}
甚至我们尝试为 proxyHost 和 proxyPort 添加一些系统属性
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxyHost", "yyyy.com");
System.setProperty("ftp.proxyPort", "80");
System.setProperty("ftp.proxyHost", "yyyy.com");
System.setProperty("socksProxyPort", "80");
System.setProperty("socksProxyHost", "yyyy.com");
错误信息
Could not connect to server.
java.net.UnknownHostException: ftp.xxxx.com
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at java.net.InetAddress.getByName(InetAddress.java:969)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:192)# client disconnected
at org.apache.commons.net.SocketClient.connect(SocketClient.java:285)
at com.ti.itg.peit.bom.TestingApache.main(TestingApache.java:44)
非常感谢。
杰拉德