Hi,

A general question that isn't obvious to me from scanning the available sample 
code:


What is the convention for connecting/disconnecting Channels and Sessions? I 
got the impression that sessions and channels could be long-lived, but testing 
my code is suggesting that this might be a mistake.

As a simple example, if I want to download a list of files, should it be (in 
sort-of-pseudo-code):
        session = jsch.getSession(userId, server, 22);
        session.connect();
        ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
        channel.connect();

        for (String fname : fileList) {
            channel.get(fname, destPath);
        }

        channel.disconnect();
        session.disconnect();

Or should it be:

        session = jsch.getSession(userId, server, 22);
        session.connect();

        for (String fname : fileList) {
            ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
            channel.connect();
            channel.get(fname, destPath);
            channel.disconnect();
        }
        session.disconnect();

And should I be using setServerAliveInterval() and setDaemonThread() on the 
session?

I'm finding that my initial approach of keeping a single session and a single 
sftp channel over multiple operations results in intermittent 'inputstream 
closed' and 'pipe closed' errors.

Thanks,
Andy
------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to