【发布时间】:2017-01-17 14:44:27
【问题描述】:
我在尝试连接到 (Windows) SFTP 服务器时遇到问题。 SFTP 服务器的名称是 Secure Bridge(适用于 Windows)。 这很奇怪,因为它看起来有时可以正常工作,但有时也不能正常工作。它有时会显示如下错误。 我的来源如下。你可以帮帮我吗?为什么会出现这个错误?
[Error]
java.io.IOException: The transport protocol disconnected
com.sshtools.j2ssh.transport.TransportProtocolCommon.readMessage(Unknown Source)
com.sshtools.j2ssh.transport.TransportProtocolCommon.sendNewKeys(Unknown Source)
com.sshtools.j2ssh.transport.TransportProtocolCommon.beginKeyExchange(Unknown Source)
com.sshtools.j2ssh.transport.TransportProtocolCommon.onMsgKexInit(Unknown Source)
com.sshtools.j2ssh.transport.TransportProtocolCommon.startBinaryPacketProtocol(Unknown Source)
com.sshtools.j2ssh.transport.TransportProtocolCommon.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
private SshClient client = null;
private PasswordAuthenticationClient auth = null;
private SftpClient sftp = null;
public boolean connect(String server,
int port,
String user,
String pwd) throws Exception {
try {
if (server == null || user == null || pwd == null) {
logger.error("Parameter is null!");
throw new Exception("Parameter is null!");
}
SshConnectionProperties params = new SshConnectionProperties();
params.setHost(server);
params.setPort(port);
HostKeyVerification key = new HostKeyVerification() {
@Override
public boolean verifyHost(String arg0,
SshPublicKey arg1) throws TransportProtocolException {
return true;
}
};
client = new SshClient();
client.setSocketTimeout(10000);
client.connect(params, key);
auth = new PasswordAuthenticationClient();
auth.setUsername(user);
auth.setPassword(pwd);
int result = client.authenticate(auth);
if (result != AuthenticationProtocolState.COMPLETE) {
throw new Exception("Login to " + server + ":" + port + " " + user + "/" + pwd + " failed");
}
sftp = client.openSftpClient();
} catch (Exception e) {
logger.error(e);
logout();
return false;
}
return true;
}
【问题讨论】:
-
您是否可以使用任何 SFTP 客户端(例如 filezilla)连接到同一台服务器?
标签: java protocols sftp connect transport