There is my situation.

I want to get connected to a Server Ubuntu (let's call it Server 1) and run a script which contains sftp commands that transfers a file to a second Server (server 2).

When I am on Server 1 I can run the script and the transfer is done, but when I am using my java application with Ganymed-SSH2 to get connected to Server 1 and run the script I get Commande exitStatus 255.

When I use putty to get connected to Server 1 and run the script, I'm asked to give the passphrase even if I copied the passphrase in "authorized_keys" of Server 2.

There is the script I run:

Java Code:
sftp login@server <<EOF
put file
And this is the java code I'm using:

Java Code:
Connection connection=new Connection("SERVEUR");
		try {
			connection.authenticateWithPassword("login", "password");
			System.out.println("Connection Established");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println("Connection Failed");
		Session session=connection.openSession();
        System.out.println( "ExitCode: " + session.getExitStatus() );

Hope someone can help me.