2017-12-11 7 views
0

SFTP 서버에 파일을 업로드하기 위해 Java 코드 (apache common vfs2 사용)를 작성했습니다. 최근에 내 서버에 PGP 보안을 도입했습니다. 자, 자바 코드는이 서버에 연결할 수 없습니다. FileZilla와의 연결에 성공했습니다. 우리는 서버에서 CrushFTP를 사용하고 Java 응용 프로그램에서는 apache-common-vfs2를 사용합니다. 다음 코드는 Anoney 솔루션을 제안 해주십시오SFTP 서버에 연결할 수 없습니다. Apache common

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) 

따를

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; 
} 

예외는 니펫을한다?

+0

SFTP는 OpenPGP 프로토콜을 전혀 지원하지 않지만 대신 TLS 표준을 사용합니다. TLS로 암호화 된 SFTP 채널을 통해 페이로드로 OpenPGP 암호화 파일을 전송할 수 있지만 (SFTP 전송은 OpenPGP와 전혀 관련이 없습니다.) –

답변

1

오류 메시지는 1024 비트보다 큰 Java release older than 1.8Diffie-Hellman 매개 변수를 사용 중임을 나타냅니다. JDK 릴리스를 1.8 이상으로 업데이트하거나 서버 측에서 1024 비트 Diffie-Hellman 매개 변수로 제한하십시오 (수행 방법은 사용중인 서버 소프트웨어에 따라 다르며 서버 구성 작업은 Server Fault에 문의하는 것이 좋습니다).

관련 문제