I had working code the other day for a simple connect and file upload using vfs2. Suddenly, the method stopped working, and I began to receive:
java.io.IOException: Logon failure: unknown user name or bad password
I tried three different users who I can use to access the sftp server, but no luck. Upon purposely misspelling my password or username, I receive a different error:
org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server
Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server
Caused by: com.jcraft.jsch.JSchException: Auth fail
Not sure how much program goes working perfectly one day to logon failure another. I didn't change anything. My code for my method:
public static void encryptFile(File input, File output)
{
FileSystemManager fsManager;
try {
/*SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
FileSystemOptions fsOptions = new FileSystemOptions();
builder.getKnownHosts(fsOptions);
builder.setUserDirIsRoot(fsOptions, false);
builder.setTimeout(fsOptions, 5000);*/
FileSystemOptions fsOptions = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no");
fsManager = VFS.getManager();
String uri = "sftp://" + Env.getFtpUserEncrypt() + ":" +
Env.getFtpPassEncrypt() + "@" + Env.getFtpUrlEncrypt() + "/app/" + input.getName();
FileObject dest = fsManager.resolveFile(uri, fsOptions);
String filePath = input.getCanonicalPath();
FileObject orig = fsManager.resolveFile(filePath, fsOptions);
dest.copyFrom(orig, Selectors.SELECT_SELF);;
} catch (Exception e)
{
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
String temp = errors.toString();
log.error("Error putting file onto ftp: " + temp);
return;
}
}
Edit: Env is just a class used for defining my credential variables. In this case, Env is used to define my username, password, and url for the connection.
What would most likely cause this problem? Is it a bug, or is my authentication actually wrong?