現在、Apache vfs2 を使用して sftp からファイルをダウンロードしています。認証には、ユーザー名とパスワードを使用します。
vfs2 を public-private-keys のみで、パスワードなしで使用する方法はありますか?
私はこの機能を使用したと思いますが、どのように?「はい」のみに設定しますか?
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
これは私の現在のコードです(スニペット):
private boolean downloadFile(){
StandardFileSystemManager sysManager = new StandardFileSystemManager();
//download der Datei
try {
sysManager.init();
FileObject localFile = sysManager.resolveFile(localFilePath);
FileObject remoteFile = sysManager.resolveFile(createConnectionString(host, user, password, fileName, port),createDefaultOptions());
//Selectors.SELECT_FILES --> A FileSelector that selects only the base file/folder.
localFile.copyFrom(remoteFile, Selectors.SELECT_FILES);
} catch (Exception e) {
logger.error("Downloading file failed: " + e.toString());
return false;
}finally{
sysManager.close();
}
return true;
}
と
private FileSystemOptions createDefaultOptions() throws FileSystemException{
//create options for sftp
FileSystemOptions options = new FileSystemOptions();
//ssh key
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no");
//set root directory to user home
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, true);
//timeout
SftpFileSystemConfigBuilder.getInstance().setTimeout(options, timeout);
return options;
}