-1

Have a server https://abcxx.com and need to upload a file to this at location https://abcxx.com/internalfolder/ . Have obtained a proxy for the server with a proxy host and proxy port. How to connect to this proxy and send the file to the required folder? Tried few examples but not much success.

URL weburl = new URL("https://abcxx.com");
        Proxy socksProxy 
          = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyhost", proxyport));
        HttpURLConnection socksConnection 
          = (HttpURLConnection) weburl.openConnection(socksProxy);

Iam new to networking so im not sure if iam doing this right in above sample code.

  • Are you using any library for doing connection? like Apache httpclient. – Dhaval Gajjar Oct 11 '22 at 13:19
  • Only libraries im using are mentioned in above code snippet: import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Socket; import java.net.URL; – Naveen kumar Oct 11 '22 at 13:52
  • Checkout https://stackoverflow.com/questions/1432961/how-do-i-make-httpurlconnection-use-a-proxy. It has different options to use proxy. – Dhaval Gajjar Oct 11 '22 at 14:06
  • In the given link, in the code there is urlstring, which url should i use here? The actual server url in my case https://abcxx.com or the intended folder https://abcxx.com/internalfolder/ – Naveen kumar Oct 11 '22 at 14:09
  • The url should be the intended folder. Else it will try to upload at abcxx.com but you want the file to be uploaded at abcxx.com/internalfolder. – Dhaval Gajjar Oct 11 '22 at 14:14
  • I tried this ````Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyhost", proxyport)); conn = new URL("https://abcxx.com/internalfolder/").openConnection(proxy);```` And 403 is the response – Naveen kumar Oct 11 '22 at 14:17
  • Does your proxy have authentication required? username/password. If yes then please configure it samples in that given link. If not required then please check your API it seems you don't have permission to upload. – Dhaval Gajjar Oct 12 '22 at 02:56

1 Answers1

0
jschSession = jsch.getSession("username", "abcxx.com", 22);
    jschSession.setProxy(new ProxyHTTP(proxyhost:proxyport));

    // authenticate using password
    jschSession.setPassword(password));
    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    jschSession.setConfig(config);

    // 10 seconds session timeout
    jschSession.connect(10000);

    Channel sftp = jschSession.openChannel("sftp");

    // 5 seconds timeout
    sftp.connect(5000);

This solved my issue