I am trying to user the StaticUserAuthenticator with an FTP connection through ApacheVFS2 - I have the following code:
this.fsOptions = new FileSystemOptions();
StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fsOptions, auth);
this.fsManager = VFS.getManager();
// ... later
FileObject file = fsManager.resolveFile("ftp://myhost:21/pathtofile.ext".toString(), fsOptions);
FileContent content = file.getContent();
This results in the following exception being thrown:
org.apache.commons.vfs2.FileSystemException: Could not read file "ftp://myhost:21/pathtofile.ext". Caused by: sun.net.ftp.FtpLoginException: user anonymous : 501 Use user@site to connect via proxy
When I run a network trace on this I see that the user arg passed to the FTP server is 'anonymous' T 10.161.37.176:57650 -> 10.152.4.138:21 [AP] USER anonymous..
Any idea what I'm doing wrong?
Ok, not as tricky as I thought
UserAuthenticator auth = new StaticUserAuthenticator("", username, password);
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fsOptions, auth);
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fsOptions, true);
Not sure if it's the non-null first arg to the StaticUserAuthenticator constructor, or the passive mode that did it, but with those changes it works.