We've handled this by coding put and get methods that call the jsch
stuff in what amounts to a wrapper class and put methods' code in
try/catch blocks that concludes with this finally clause to ensure the
channel gets closed in the case of an abnormal exit:

          } finally {
               try {
                    if (channel != null && channel.isConnected()) {
                     channel.disconnect();
                    }
                    if (session != null && session.isConnected()) {
                     session.disconnect();
                    }
               } catch (Exception e) {
                    logger.warn("Unable to close channel/session. " +
e.getMessage(), e);
                   }
                   ;
          }
        

~~~~~~~~~~~~~~~~~~~~~~~
Joe Magid 
Senior Developer
ING - Annuity Manufacturing IT Production Support
Office: (610) 425-3750 
Cell:    (610) 506-4595
[email protected] <blocked::mailto:[email protected]> 

 

________________________________

From: CHEN Xiaolei A [mailto:[email protected]] 
Sent: Friday, December 10, 2010 03:10 AM
To: [email protected]
Subject: [JSch-users] can sftpchannel close itself automatically?



Hi, 

   I use JSCH to implement a SFTP client,  all work well except one
problem:  If the method "ChannelSftp.disconnect()" is not called,
process will hang when stopping. 

   In normal exit case, that method could be called;  But if  process
exits in a abnormal way, and that method can not be called, I am afraid
that the hang problem will occur. 

   So I want to know whether there is some method in JSCH to set
"TIMEOUT" for a sftp session, once reaching the time, corresponding
session and sftpchannel will close automatically.

   My use-case: 
   JSch jsch=new JSch(); 
   Session session=jsch.getSession("XXX", "XXX", 22); 
   UserInfo ui=new MyUserInfo(); 
   session.setUserInfo(ui); 
   session.connect(); 
   Channel channel=session.openChannel("sftp"); 
   channel.connect(); 
   ChannelSftp channel=(ChannelSftp)channel; 
   //do some file transfer using channel 
   ... 

   //when shutting down process 
   channel.disconnect(); 
   session.disconnect(); 

   Thanks. 

Regards, 
Atlantis 


---------------------------------------------------------

NOTICE: The information contained in this electronic mail message is 
confidential and intended only for certain recipients.  If you are not an 
intended recipient, you are hereby notified that any disclosure, reproduction, 
distribution or other use of this communication and any attachments is strictly 
prohibited.  If you have received this communication in error, please notify 
the sender by reply transmission and delete the message without copying or 
disclosing it.

============================================================================================
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to