FTPS client behind a proxy server using apache commons net

Terra-X

New Member
Our network team only allow us to connect to our third party client thru proxy server.
Is there a way to add a proxy server to FTPS client of apache commons net?
If it is not possible, can you tell a way on how to do it.By the way here's the code that is working outside of the company network\[code\]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(); }\[/code\]even we tried to add some system property for proxyHost and proxyPort\[code\]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");\[/code\]error message\[code\]Could not connect to server.java.net.UnknownHostException: ftp.xxxx.comat 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 disconnectedat org.apache.commons.net.SocketClient.connect(SocketClient.java:285)at com.ti.itg.peit.bom.TestingApache.main(TestingApache.java:44)\[/code\]Thank you very much.Gerald
 
Top