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;
}
예외는 니펫을한다?
SFTP는 OpenPGP 프로토콜을 전혀 지원하지 않지만 대신 TLS 표준을 사용합니다. TLS로 암호화 된 SFTP 채널을 통해 페이로드로 OpenPGP 암호화 파일을 전송할 수 있지만 (SFTP 전송은 OpenPGP와 전혀 관련이 없습니다.) –