1

我正在尝试通过 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中找到,下面是网址

https://github.com/sshtools/j2ssh-maverick/blob/master/j2ssh-maverick/src/main/java/com/sshtools/net/SocksProxyTransport.java

connectViaSocks5Proxy 方法。

第 204 行。

那么有什么方法可以指定身份验证方法吗?

4

0 回答 0