-1

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?

antihero989
  • 486
  • 1
  • 10
  • 32
  • What is `Env`? Please include all relevant information. – Jim Garrison Sep 04 '14 at 16:41
  • 1
    It is impossible for anyone to help you unless you provide ALL the relevant information. For example, what does `Env.getFtpPassEncrypt()` actually do? Include the source code. Put yourself in our position and ask yourself what you would need if you hadn't written the code and were asked to debug it. – Jim Garrison Sep 04 '14 at 16:53
  • @JimGarrison Why would I include code that has sensitive information? I told you what it deliberately does. It's a variable that is my password. Likewise with the other two, they define my username and url. – antihero989 Sep 04 '14 at 16:59

1 Answers1

0

I tried connected to a different server using the same credentials and this was able to connect no problem. I then retried the server that I was experiencing problems with and this seemed to somehow "wake it up" and connect with no given error. Not sure why this would help correct the error, but it is a work around nevertheless.

antihero989
  • 486
  • 1
  • 10
  • 32