title: How to transfer a file using a proxy with JSch library
body: <p>I want to transfer 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 :</p>
  
  <pre class="lang-none prettyprint-override"><code>sftp -o "ProxyCommand /usr/bin/nc -X connect -x &lt;proxy_host&gt;:&lt;proxy_port&gt; %h %p" username@ftp_server:
  </code></pre>
  
  <p>But I want to automate this process of file transfer and I am using JSch for SFTP and snippet of code is below: </p>
  
  <pre><code>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(&lt;proxy_host&gt;, &lt;proxy_port&gt;));
  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);
  </code></pre>
  
  <p>With above code I am getting following exception: </p>
  
  <pre class="lang-none prettyprint-override"><code>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)
  </code></pre>