gpt4 book ai didi

Java SSH 工具 : SftpClient error: The remote computer disconnected: Protocol error: packet too long: 65580

转载 作者:行者123 更新时间:2023-11-30 05:15:24 32 4
gpt4 key购买 nike

当我尝试执行时,我收到“信息:远程计算机已断开连接:协议(protocol)错误:数据包太长:65580”错误:

sUpload("server.host.com", "username", "/home/localuser/.ssh/id_rsa", "filename", "");

文件不会传输到 SFTP 服务器(另一端仅创建零字节)。当通过 Unix shell 手动进行 SFTP 时,一切正常。我在网上读到,这可能是 SftpClient 中 BLOCK_SIZE 的问题,但首先我找不到更改大小的 setter 方法,其次,默认值似乎是 65535,这完全不能解释错误中的 65580 值消息。

有什么想法吗?

我有以下使用 Java Ssh 工具 (j2ssh-core-0.2.9.jar) 的实用方法:

private static void sUpload(String ftpServer, String user, String password,
String localFile, String remoteFile) throws IOException {
String methodName = "sUpload: ";
System.out.println(" START ftpServer="+ftpServer+" user="+user+" password="+password);

int result = 0;
System.out.println("ftpServer " + ftpServer);
System.out.println("user " + user);
System.out.println("password " + password);
System.out.println("localFile " + localFile);
System.out.println("remoteFile " + remoteFile);

SshClient ssh = new SshClient();

ssh.connect(ftpServer);

System.out.println("Server Connected ");
if (password.contains("\\") || password.contains("/")) {

PublicKeyAuthenticationClient pk =
new PublicKeyAuthenticationClient();

pk.setUsername(user);
// Open up the private key file
SshPrivateKeyFile file = SshPrivateKeyFile
.parse(new File(password));
SshPrivateKey key = file.toPrivateKey(null);
pk.setKeyfile(password);
pk.setKey(key);
// Try the authentication
result = ssh.authenticate(pk);

} else {

// Create a password authentication instance
PasswordAuthenticationClient pwd =
new PasswordAuthenticationClient();
// Get the users name
pwd.setUsername(user);
// Get the password
pwd.setPassword(password);

// Try the authentication
result = ssh.authenticate(pwd);
}

System.out.println("Result fromssh.authenticate(pwd) " + result);
// Evaluate the result
if (result == AuthenticationProtocolState.COMPLETE) {

// The connection is authenticated we can now do some real work!
SftpClient sftp = ssh.openSftpClient();
System.out.println("openSftpClient");
// Upload a file
if(remoteFile != null && remoteFile.trim().length() > 0){
sftp.put(localFile, remoteFile);
System.out.println("======== no remote ======================================== file transfer success =======================================================================");
}
else {
System.out.println("================================================ file transfer starting =======================================================================");
sftp.put(localFile);
System.out.println("================================================ file transfer success =======================================================================");
}


// Quit
sftp.quit();
ssh.disconnect();
}
System.out.println(" END ");
}

最佳答案

ssh 客户端应告诉服务器所需的最大数据包大小是多少,并且服务器遵守规范。

尝试不同的服务器并检查您自己服务器的最大数据包大小的配置。

关于Java SSH 工具 : SftpClient error: The remote computer disconnected: Protocol error: packet too long: 65580,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1627516/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com