我正在尝试使用 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);