【问题标题】:Apache Vfs Error in FTP file download "could not copy filename because it does not existFTP 文件下载中的 Apache Vfs 错误“无法复制文件名,因为它不存在
【发布时间】: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


    【解决方案1】:

    我遇到了类似的问题。通过将用户目录设置为root解决它

    FtpFileSystemConfigBuilder.getInstance( ).setUserDirIsRoot(opts,true);
    

    这里给出原始答案和解释-https://stackoverflow.com/a/16358024/2845937

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-13
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多