org.apache.commons.vfs2 を使用して、SFTP 経由でファイルをダウンロードしようとしています。問題は、パスワードに「@」文字が含まれているため、URI が正しく解析されないことです。
org.apache.commons.vfs2.FileSystemException: Expecting / to follow the hostname in URI
この問題を回避する方法を知っている人はいますか? (もちろん、パスワードを変更することはできません)。これは私が使用しているコードです:
String sftpUri = "sftp://" + userName + ":" + password + "@"
+ remoteServerAddress + "/" + remoteDirectory + fileName;
String filepath = localDirectory + fileName;
File file = new File(filepath);
FileObject localFile = manager.resolveFile(file.getAbsolutePath());
FileObject remoteFile = manager.resolveFile(sftpUri, opts);
localFile.copyFrom(remoteFile, Selectors.SELECT_SELF);