We are attempting to put files from Solaris 10 server to a Novell sftp server 
running NetWare OpneSSH sftp-server(NICI) 3.7.1p6 build 80).  Using jsch 1.44.  
We are going throught a firewall.  What happens is that when putting the file, 
it will just stop and not exchange any data with the server.  We have looked at 
the connection using network sniffers and see no traffic at all.  Just stops.  
If the connection is broken by the network people, the code throws an exception 
as it should.  Has anyone seen this behavior?  Any solution?  This happens 
sometimes, maybe one out of 5 tries, and it's usually with larger files 300MB 
and up, although it has happened on files as little as 9MB.  If it stops, the 
part of the file transferred is still there on the target server.   In my code, 
each file has a fresh connection created for that transmission.  I've tried 
setting a timeout, calling setTimeout() on the session - no difference.  Also 
tried calling session.setServerAliveInterval() - nothing.  Maybe the answer 
lies in starting a separate thread and calling session.sendKeepAliveMsg()?  
Following is the code:


JSch jsch=new JSch();
        Session session=null;
        Channel channel=null;
        ChannelSftp c=null;
 
        Hashtable hashtable = new Hashtable();
 
        hashtable.put("StrictHostKeyChecking","no");
 
        //SFTP default port is 22
 
        try {
            session=jsch.getSession(User, Host, Port);
        } catch (JSchException ex) {
            throw new Exception("getSession Exception: " + ex.getMessage());
        }
        session.setConfig(hashtable);
        session.setPassword(Password);
        try {
            session.connect();
        } catch (JSchException ex) {
            throw new Exception("session.connect Exception: " + 
ex.getMessage());
        }
        try {
            channel=session.openChannel("sftp");
        } catch (JSchException ex) {
            throw new Exception("session.openChannel Exception: " + 
ex.getMessage());
        }
        try {
            channel.connect();
        } catch (JSchException ex) {
            throw new Exception("channel.connect Exception: " + 
ex.getMessage());
        }
 
        try {
            c=(ChannelSftp)channel;
        } catch (Exception ex) {
            throw new Exception("(ChannelSftp)channel Exception: " + 
ex.getMessage());
        }
        //check if file exists
        SftpATTRS sftpATTRS = null;
        Boolean fileExists = true;
        try {
            sftpATTRS = c.lstat(RemoteTargetFolder + Filename);
        } catch (Exception ex) {
                    fileExists = false;
            }
 
        if (Overlay == true & fileExists) { //allowed to overlay and file exists
                try {
                        c.rm(RemoteTargetFolder + Filename);
             } catch (Exception ex) {
                         c.quit();
                session.disconnect();
                throw new Exception("rm Exception on existing file: " + 
RemoteTargetFolder + Filename + " " + ex.getMessage());
             }
             }
         if (Overlay == false & fileExists) { //not allowed to overlay and file 
exists
                                c.quit();
                session.disconnect();
                throw new Exception("File " + Filename + " exists in directory 
" + RemoteTargetFolder);
             }
             // check if compression
             if (Compression == true) {
                          session.setConfig("compression.s2c", 
"z...@openssh.com,zlib,none");
              session.setConfig("compression.c2s", 
"z...@openssh.com,zlib,none");
                  }
 
         //check if using temp file
         String filename = null;
         if (UseTempFile == true) {
             filename = TempFileName;
          }
          else {
              filename = Filename;
          }
 
            try {
                c.put(LocalFullPathFileName, RemoteTargetFolder + filename);
            } catch (Exception ex) {
                try {  //clean up file
                    c.rm(RemoteTargetFolder + RemoteTargetFolder + filename);
                } catch (Exception ex2) {
                }
                c.quit();
                session.disconnect();
                throw new Exception("put Exception: " + ex.getMessage());
            }
            if (UseTempFile == true) {
                try {
                    c.rename(RemoteTargetFolder + TempFileName, 
RemoteTargetFolder + Filename);
                } catch (Exception ex) {
                    try {
                        c.rm(RemoteTargetFolder + TempFileName);
                    } catch (Exception ex2) {
                    }
                    c.quit();
                    session.disconnect();
                    throw new Exception("rename Exception: " + ex.getMessage());
                }
                try {
                    c.chmod(0664, RemoteTargetFolder + Filename);
                } catch (Exception ex) {
                }
            }
        c.quit();
        session.disconnect();


 


------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy 
to use, easy to manage, easy to install, easy to extend. 
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to