0

I'm trying to download a file via an ftp(s) server with apache vfs. Here is the code:

`

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

`

I can connect seamlessy to the server,and I can retrieve path,type (which is file) and uri. All seems correct but the copyFrom gives: Could not copy "my filename" because it does not exist. at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:271)

I'm running on windows and I can download the file via Filezilla or winscp without problems

Moebius
  • 73
  • 7

1 Answers1

0

I was facing the similar issue. Resolved it by setting user directory as root

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

The original answer and explanation is given here - https://stackoverflow.com/a/16358024/2845937