sftp java client
<p>I am able to connect to server2 via sftp at server1 using public key . But I am facing "Auth fail" error while connecting server 2 from server1 via java code</p>

<p>public key is already setup at both servers</p>

<p>Can you let me know where I am wrong?</p>

<pre><code>ChannelSftp channelsftp = null;
            Session session = null ;       
            Map&lt;String,String&gt; envMap = getEnvMap();
            OutputStream outFile = null ;
            BufferedInputStream in = null ;
            File file = new File(fileName);
            try
            {
                String host = "server.net";
                String user = "test";
                String key = "id_dsa";
                JSch jsch = new JSch();
                try
                {
                    jsch.addIdentity(new File(key).getAbsolutePath());

                    session = jsch.getSession(user, host,22);

                    Properties properties = new Properties();
                    properties.put("StrictHostKeyChecking", "no");
                    properties.put("PreferredAuthentications", "publickey");
                    session.setConfig(properties);
                    System.out.println("before making Connection:"+session);
                    session.connect();
                    System.out.println("Connection successful");
                    Channel channel = session.openChannel("sftp");
                    channel.connect();
                    channelsftp = (ChannelSftp)channel;
                }catch(Exception e) {
                    e.printStackTrace();
                    throw e;
                }

            }
</code></pre>

<p>I am getting "Auth fail' at session.connect() </p>
