如何将Apache Mina sftp客户端配置为使用代理



我想在Java应用程序中使用Apache MINA作为sftp客户端。此应用程序将通过HTTPS代理与远程服务器建立出站连接。我需要设置连接到某个代理的身份验证详细信息。

我想通过代理获取一个在ssh连接上运行的org.apache.sshd.sftp.client.SftpClient实例。

我有这些进口商品:

import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientProxyConnector;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.SftpClientFactory;

这是我迄今为止写的代码:

// proxy
ClientProxyConnector proxy = ????;
// ssh
SshClient sshClient = SshClient.setUpDefaultClient();
sshClient.setClientProxyConnector( proxy );
sshClient.start();
ClientSession sshSession = sshClient.connect( "example.org" ).getSession();
// sftp
SftpClientFactory factory = SftpClientFactory.instance();
SftpClient client = factory.createSftpClient(sshSession);

问题:

  • 我需要ClientProxyConnector的实例来执行我要执行的操作吗
  • 如何获取ClientProxyConnector的实例并使用代理身份验证详细信息对其进行配置

要检查代理,您应该使用允许指定代理的HostConfigEntry创建ClientSession

HostConfigEntry host = new HostConfigEntry("", "example.org", 22, "username", 
proxyUser + "@" + proxyHost + ":" + proxyPort);
ClientSession sshSession = sshClient.connect(host).getSession();

ClientProxyConnector的目的是另一回事。

最新更新