我尝试从Linux服务器连接并下载文件,但在使用jscape
java库连接到服务器时遇到以下异常。
编号
package com.example.util;
import com.jscape.inet.sftp.Sftp;
import com.jscape.inet.ssh.util.SshParameters;
public class TestFTPManager
{
private static final String hostname = "mycompany.example.com";
private static final String username = "exampleuser";
private static final String password = "examplepassword";
private static final int port = 22;
private Sftp sftpClient;
public TestFTPManager()
{
this.sftpClient = new Sftp( new SshParameters(hostname, port, username, password ));
}
public void connect() throws Exception
{
this.sftpClient.connect();
}
public void setAscii() throws Exception
{
this.sftpClient.setAscii();
}
public void setBinary() throws Exception
{
this.sftpClient.setBinary();
}
public Sftp getSftpClient()
{
return sftpClient;
}
public void setSftpClient( Sftp sftpClient )
{
this.sftpClient = sftpClient;
}
public static void main(String[] args)
{
try
{
TestFTPManager sftpManager = new TestFTPManager();
sftpManager.getSftpClient().connect(); // Error
System.out.println( "Connection successful!" );
// download operation is done here.
sftpManager.getSftpClient().disconnect();
System.out.println( "Disconnection successful!" );
} catch (Exception e)
{
e.printStackTrace();
}
}
}
错误
com.jscape.inet.sftp.SftpException: cause: java.util.NoSuchElementException: no common elements found
at com.jscape.inet.sftp.SftpConfiguration.createClient(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
at com.example.util.TestFTPManager.main(TestFTPManager.java:54)
Caused by: com.jscape.inet.ssh.transport.TransportException: cause: java.util.NoSuchElementException: no common elements found
at com.jscape.inet.ssh.transport.AlgorithmSuite.<init>(Unknown Source)
at com.jscape.inet.ssh.transport.TransportClient.getSuite(Unknown Source)
at com.jscape.inet.ssh.transport.Transport.exchangeKeys(Unknown Source)
at com.jscape.inet.ssh.transport.Transport.exchangeKeys(Unknown Source)
at com.jscape.inet.ssh.transport.TransportClient.<init>(Unknown Source)
at com.jscape.inet.ssh.transport.TransportClient.<init>(Unknown Source)
at com.jscape.inet.ssh.SshConfiguration.createConnectionClient(Unknown Source)
at com.jscape.inet.ssh.SshStandaloneConnector.openConnection(Unknown Source)
... 4 more
Caused by: java.util.NoSuchElementException: no common elements found
at com.jscape.inet.ssh.types.SshNameList.getFirstCommonNameFrom(Unknown Source)
at com.jscape.inet.ssh.transport.AlgorithmSuite.a(Unknown Source)
at com.jscape.inet.ssh.transport.AlgorithmSuite.h(Unknown Source)
... 12 more
然而,当我在服务器的/etc/ssh/sshd_config
文件中注解了以下几行(第23,23,25行)时,我可以成功地从服务器连接并下载文件,没有任何异常。
问:如何在不注解服务器中的/etc/ssh/sshd_config
文件(第23、23、25行)的情况下消除此异常?我希望您能解释一下为什么我也会出现此异常。
1条答案
按热度按时间n6lpvg4x1#
如果您遇到此问题,请检查以下结果。
我使用的是JSCAPE(Java)库8.8.0版。根据我的理解,这个版本不支持
sshd_config
文件中指定的一些Ciphers和KexAlgorithms。当您参考JSCAPE文档时,
com.jscape.inet.sftp
类包含设置密钥交换、密码、mac和压缩(如果需要)所需的内容。Please click here to see the official documentation,在那里您可以看到如何将这些内容放入代码中。但是,我使用的JSCAPE(Java)库(版本8.8.0)不包含这些类和方法,如果需要的话,这些类和方法可以用来设置密钥交换、密码、MAC和压缩。
您可以尝试使用最新版本的JSCAPE库,但我怀疑它是否可以免费获得。