2

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);
4

1 に答える 1

4

独自の URI コンストラクターを手動で作成する代わりに、実際の URI コンストラクターを使用します。

String userInfo = userName + ":" + password;
String path = remoteDirectory + filename;  // Need a '/' between them?
URI sftpUri = new URI("sftp", userInfo, remoteServerAddress, -1, path, null, null);
...
FileObject remoteFile = manager.resolveFile(sftpUri.toString(), opts);
于 2014-10-19T14:56:16.257 に答える