【问题标题】:How to enter into passive mode with Apache SSHD如何使用 Apache SSHD 进入被动模式
【发布时间】:2015-11-26 05:59:33
【问题描述】:

我有以下代码使用 Apache Mina SSHD 创建远程 ChannelSubsystem(FTP 客户端):

org.apache.sshd.client.channel.ChannelSubsystem c = session.createSubsystemChannel("sftp");

int authState = ClientSession.WAIT_AUTH;

while ((authState & ClientSession.WAIT_AUTH) != 0) {

    System.out.println("authenticating...");

    authFuture.addListener(new SshFutureListener<AuthFuture>()
    {
        @Override
        public void operationComplete(AuthFuture arg0)
        {
            System.out.println("Authentication completed with " + ( arg0.isSuccess() ? "success" : "failure"));
        }
    });

    authState = session.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0);
}

if ((authState & ClientSession.CLOSED) != 0) {
    System.err.println("error");
    System.exit(-1);
}

OpenFuture openFuture = c.open().await();

如何通过ChannelSubsystem向远程FTP站点发送命令进入被动模式?

【问题讨论】:

  • 你认为为什么需要使用被动模式?

标签: java ftp apache-mina sshd


【解决方案1】:

您正在使用 SSH/SFTP,而不是 FTP 进行连接。

SFTP 中的主动/被动模式完全不同。


主动/被动模式与 FTP 协议不同,因为它使用单独的数据连接。在主动模式下,服务器发起数据连接。在被动模式下,客户端启动连接。
有关详细信息,请参阅我在FTP connection modes 上的文章。

SFTP 中没有单独的数据连接,因此没有理由使用主动/被动模式。

【讨论】:

  • 马丁,非常感谢您的宝贵帮助。你知道为什么当我在 DefaultSftpClient.getOut() 流中写入一个 Buffer 时,DefaultSftpClient.getIn() 流仍然是 null..client 已连接。我还以为是被动模式的问题,现在不知道了
  • 不客气。请开始一个新问题。这是问答网站,不是论坛。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-12
  • 2020-10-22
  • 2020-11-14
  • 2013-06-20
  • 2013-09-25
  • 1970-01-01
相关资源
最近更新 更多