我正在尝试通过socks5代理服务器从独立的sftpclient连接到SFTP服务器,我正在使用maverick-all库。我的代码运行正常。以下是代码段:
private SshClient getSSHClient() throws Exception {
SshClient ssh = null;
SshClient forwardedConnection = null;
/**
* Create an SshConnector instance
*/
SshConnector con = SshConnector.getInstance();
Ssh2Context context = (Ssh2Context) con.getContext(SshConnector.SSH2);
setupContext(context);
context.setHostKeyVerification(new ConsoleKnownHostsKeyVerification());
SocketTransport t = new SocketTransport(hostname, port);
t.setTcpNoDelay(true);
//System.out.println("t.isConnected() ->" + t.isConnected());
ssh = con.connect(t, username, true);
PasswordAuthentication pwd = new PasswordAuthentication();
pwd.setPassword(password);
ssh.authenticate(pwd);
if (ssh.isAuthenticated()) {
System.out.println("authenticated");
// Connect via socks5 proxy
SshTransport spt = SocksProxyTransport.connectViaSocks5Proxy(hostname, port, proxyServerHost, proxyServerPort, proxyServerUsername,proxyServerPassword);
forwardedConnection = con.connect(spt, username);
PasswordAuthentication pwd2 = new PasswordAuthentication();
pwd2.setPassword(password);
forwardedConnection.authenticate(pwd2);
}
return forwardedConnection;
}
我现在想要不使用代理身份验证,即不使用代理用户名和密码,因为代理服务器(CCproxy)允许这样的配置。如果我们将方法指定为'0',我查看了库代码。代码可以在github中找到,下面是URL
connectViaSocks5Proxy方法。
第204行。
那么有没有办法指定身份验证方法?