This is working code from a production system to do file transfers

jsch = new JSch();
            JSch.setConfig("StrictHostKeyChecking", "no");
            session = jsch.getSession(userID, host, port);
            if (useKey) {
              jsch.addIdentity(keyFile, keyFilePassword);
            } else {
              session.setPassword(password);
            }
            session.connect();
            sftpChannel = (ChannelSftp)session.openChannel("sftp");
            sftpChannel.connect();


Rich



On 3/6/13 9:57 AM, "Don Campbell" <gal...@nycap.rr.com> wrote:

>Hi,
>
>I've tried different permutations of connecting first, then opening the
>channel; 
>and the reverse.  And some other modifications, but cannot get rid of the
>'session is down' message.
>
>This happens whether I run it in Windows, or Linux.  I confirmed that the
>host 
>is available, with the given parameters.
>
>In the code below, the error happens at the
>
>            chn_RezLife = session.openChannel( "exec" );
>
>
>or
>
>            chn_RezLife = session.openChannel( "shell" );
>
>
>statement.
>
>
>Here's the code, watered-down:
>
>import com.jcraft.jsch.*;
>
>import java.io.FileInputStream;
>
>
>public class FileTransferSFTP {
>
>    public static void main(String[] args) throws Exception {
>
>        FileTransferSFTP sendftp = new FileTransferSFTP();
>
>        sendftp.SendSFTP();
>
>    }
>
>    public void SendSFTP()
>    {
>        String sUserName = "cwhatthe";
>        String sPassword = "97whyyou";
>        int nPort = 22;
>        String sKnownHostsFileName = "blahblah.blah.com";
>        String sSourcePath = "";
>        String sDestinationPath = "";
>        JSch jsch = new JSch();
>        Session session;
>        FileInputStream fis_employeeList = null;
>        Channel chn_WhatThe = null;
>        String sSendCommand = "";
>
>
>
>        try
>        {
>            session = jsch.getSession( sUserName, sKnownHostsFileName,
>nPort );
>            session.setPassword((sPassword));
>            sSourcePath = "employeeList.csv";
>            System.out.println( "Set sSourcePath" );
>            // sDestinationPath = "/employeelists/employeeList.csv";
>            sDestinationPath = "/employeeListTest.csv";
>            System.out.println( "Ready to open channel" );
>            // chn_WhatThe = session.openChannel( "shell" );
>            chn_WhatThe = session.openChannel( "exec" );
>            System.out.println( "Opened shell channel" );
>            System.out.println( "Ready to connect" );
>            chn_WhatThe.connect(30000);
>            System.out.println( "Connected" );
>            chn_WhatThe.setInputStream((null));
>            chn_WhatThe.getInputStream();
>
>
>        }
>        catch( Exception e )
>        {
>            System.out.println( e );
>        }
>
>    }
>
>
>
>}
>
>
>
>--------------------------------------------------------------------------
>----
>Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
>Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
>endpoint security space. For insight on selecting the right partner to
>tackle endpoint security challenges, access the full report.
>http://p.sf.net/sfu/symantec-dev2dev
>_______________________________________________
>JSch-users mailing list
>JSch-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/jsch-users
>


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to