【发布时间】:2020-04-30 13:28:13
【问题描述】:
我正在尝试通过具有 apache vfs 的 ftp(s) 服务器下载文件。 代码如下:
`
String fileToDownload="testdownload.txt";
FileSystem fs = null;
FileSystemOptions opts = new FileSystemOptions();
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
FileSystemManager manager = VFS.getManager();
//
// Create local file object
String filepath = "d:\\butta\\" + "stoca.txt";
File file = new File(filepath);
FileObject localFile = manager.toFileObject(file);
FileObject remote = manager.resolveFile("ftps://user:pwd@ftp-test/DOWNLOAD/"+fileToDownload,opts);
//fs = remote.getFileSystem();
System.out.println("path is:" + remote.getName().getPath());
System.out.println("tipe is: " + remote.getName().getType());
System.out.println("uri is: " + remote.getName().getURI());
localFile.copyFrom(remote, Selectors.SELECT_SELF);
localFile.close();
remote.close();
`
我可以无缝连接到服务器,并且可以检索路径、类型(即文件)和 uri。 一切似乎都是正确的,但 copyFrom 给出了: 无法复制“我的文件名”,因为它不存在。 在 org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:271)
我在 windows 上运行,我可以通过 Filezilla 或 winscp 毫无问题地下载文件
【问题讨论】:
标签: java ftp ftps apache-commons-net