How to FTP file using a proxy WITH JSCH libraries
Clash Royale CLAN TAG#URR8PPP
How to FTP file using a proxy WITH JSCH libraries
I want to ftp files to a remote location and I am bound to use a proxy server for that. I was able to connect to the FTP location via following command :
sftp -o "ProxyCommand /usr/bin/nc -X connect -x <proxy_host>:<proxy_port> %h %p" username@ftp_server:
But I want to automate this process of file transfer and I am using Jsch for FTP and snippet of code is below:
String sourceFile = sourceDir + fileName;
JSch jsch = new JSch();
int port = Integer.parseInt(getFtpPort());
Session session = jsch.getSession(getUserName(), getHost(), port);
session.setConfig(STRICT_HOST_CHECKING, ANSWER);
session.setProxy(new ProxyHTTP(<proxy_host>, <proxy_port>));
session.setPassword(getPassword());
session.connect();
Channel channel = session.openChannel(FILE_PROTOCOL);
channel.connect();
sftpChannel = (ChannelSftp) channel;
sftpChannel.cd(desDir);
File fileToTransfer = new File(sourceFile);
sftpChannel.put(new FileInputStream(fileToTransfer), fileName);
With above code I am getting following exception:
Caused by: com.jcraft.jsch.JSchException: ProxyHTTP: java.io.IOException
at com.jcraft.jsch.ProxyHTTP.connect(ProxyHTTP.java:158)
at com.jcraft.jsch.Session.connect(Session.java:210)
at com.jcraft.jsch.Session.connect(Session.java:162)
3 Answers
3
This Worked for me
ProxyHTTP proxy = new ProxyHTTP("192.168.10.1",80)
proxy.setUserPasswd("username","password");
session.setProxy(proxy);
This worked for me.
JSch jsch = new JSch();
java.util.Properties config = new java.util.Properties();
Session session = jsch.getSession(RemoteUserName, RemoteIpAddr, RemotePortNo);
session.setPassword(RemotePassword);
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setProxy(new ProxyHTTP(ProxyName, ProxyPort));
session.connect();
This worked for me.
– Manish
Jul 14 '16 at 11:56
use
session.setProxy(new ProxySOCKS5(, ));
Instead of proxyHTTP
,
hope it works for you...
it worked for me
proxyHTTP
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Did you ever figure this one out? Facing the same issue using HTTP Proxy
– Petteri Pertola
Oct 20 '15 at 8:09