JSch puts the network proxy on the SSH Session. An SFTP channel opened over that session then uses the established route.

For an already configured session targeting the intended SSH server, select an HTTP CONNECT gateway before connecting:

ProxyHTTP gateway = new ProxyHTTP("proxy.example", 8080);
session.setProxy(gateway);
session.connect(10000);

The session still holds the SSH destination, login configuration and host-key policy. The gateway address identifies the intermediary. Its policy must allow the destination’s actual SSH port. For a publicly reachable SFTP server on an allowed public route, the HTTP proxy list offers gateway addresses for the first example. Use a new proxy adapter without proxy credentials and confirm permission for the actual SSH host and port.

For a SOCKS5 service, use the corresponding adapter instead:

session.setProxy(new ProxySOCKS5("proxy.example", 1080));

Choose the adapter matching the endpoint’s protocol. An HTTP proxy and a SOCKS listener do not understand the same negotiation.

Where JSch’s HTTP Basic proxy login is appropriate, call gateway.setUserPasswd(proxyUser, proxyPassword) before connecting. The SSH account remains configured on the session. Open the SFTP channel after the session connects, and disconnect the channel and session when the transfer is finished.

متعلقہ مضامین