无法连接到SFTP服务器Apache常见

时间:2017-12-11 13:28:23

标签: java apache file-upload sftp pgp

我已经编写了一个java代码(使用apache common vfs2)将文件上传到SFTP服务器。最近,我在我的服务器上引入了PGP Security。现在,java代码无法连接到此服务器。与FileZilla的连接成功。我们在服务器上使用CrushFTP,在java应用程序中使用apache-common-vfs2。这是代码段

String originalFileName = localFile.getName();
manager.init();
FileObject fileToUpload = manager.resolveFile(localFile.getAbsolutePath());

// Create remote file object
FileObject remoteFile = manager.resolveFile(
              createConnectionString(originalFileName),
               createDefaultFileSystemOptions());

remoteFile.copyFrom(fileToUpload, Selectors.SELECT_SELF);

方法

public String createConnectionString(String fileName) {
    String path = "sftp://" + username + ":" + password + "@" + server +workingDir+"/"+fileName;
    logger.info("uploading file at "+path);
    return path;
}

public static FileSystemOptions createDefaultFileSystemOptions()
                            throws FileSystemException {
    // Create SFTP options
    FileSystemOptions opts = new FileSystemOptions();

    // SSH Key checking
    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");

   // Root directory set to user home
   SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);

   // Timeout is count by Milliseconds
   SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
   return opts;
}

例外情况如下

Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "192.168.13.102".
    at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:170)
    at org.apache.commons.vfs2.provider.sftp.SftpFileProvider.doCreateFileSystem(SftpFileProvider.java:97)
    ... 16 more
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
    at com.jcraft.jsch.Session.connect(Session.java:565)

Anoney请建议解决方案?

1 个答案:

答案 0 :(得分:1)

错误消息表明您使用的是大于1024位的Java release older than 1.8Diffie-Hellman参数。将JDK版本更新为1.8或更高版本,或者将服务器端限制为1024位Diffie-Hellman参数(如何操作取决于所使用的服务器软件,以及Server Fault更好地询问服务器配置工作)。