Re: [JSch-users] Welcome to the "JSch-users" mailing list
Status: Alpha
Brought to you by:
ymnk
From: Heiner W. <Heiner.Westphal@Heiner-Westphal.de> - 2007-10-11 21:25:49
|
Hello! If this happens after some time of inactivity, setting keep-alive should help. Some firewalls, like checkpoint, drop inactive connections after some idle time. (Got no jsch at hands to look for the exact syntax, but I believe something like channel.setKeepAlive(true); should do - maybe it's the session though). If it happens on an active connection, I have no Idea, but the stack trace could shed some more light. Regards, Heiner Professor Flávio Brito wrote: > > Hi > > Congratulations for your work with jcraft.scp library. We are using > your jcraft library. After 2 months with success sending files to > our server, we are receiving a message "java.io.IOException: broken > channel". > We cleaned our firewall without success, but when we try it outside > our network it's OK. Can you help us? > > Thanks > > Flávio Brito > Rio de Janeiro - Brazil > > Our code > /* > * ScpToFtp.java > * > * Created on 19 de Abril de 2007, 14:46 > * > * To change this template, choose Tools | Template Manager > * and open the template in the editor. > */ > > package utils; > > import com.jcraft.jsch.*; > import java.awt.Container; > import java.awt.GridBagConstraints; > import java.awt.GridBagLayout; > import java.awt.Insets; > import java.io.File; > import java.io.FileInputStream; > import java.io.IOException; > import java.io.InputStream; > import java.io.OutputStream; > import javax.swing.JLabel; > import javax.swing.JOptionPane; > import javax.swing.JPanel; > import javax.swing.JPasswordField; > import javax.swing.JTextField; > > > /** > * > * @author renan > */ > public class ScpToFtp { > String senha=null; > > > /** Creates a new instance of ScpToFtp */ > public ScpToFtp(String fileNome,String usuario, String > passwd,String hostSsh,String portaSsh ,String fileNome2) throws > JSchException, IOException { > > > FileInputStream fis=null; > > > String lfile=fileNome; > String user=usuario; > senha = passwd; > String host=hostSsh; > String rfile=fileNome2; > > JSch jsch=new JSch(); > Session session=jsch.getSession(user, host, 8155); > > // username and password will be given via UserInfo > interface. > UserInfo ui=new MyUserInfo(); > session.setUserInfo(ui); > session.connect(); > > // exec 'scp -t rfile' remotely > String command="scp -p -t "+rfile; > Channel channel=session.openChannel("exec"); > ((ChannelExec)channel).setCommand(command); > > // get I/O streams for remote scp > OutputStream out=channel.getOutputStream(); > InputStream in=channel.getInputStream(); > > channel.connect(); > > > // send "C0644 filesize filename", where filename should > not include '/' > long filesize=(new File(lfile)).length(); > command="C0644 "+filesize+" "; > if(lfile.lastIndexOf('/')>0){ > command+=lfile.substring(lfile.lastIndexOf('/')+1); > } else{ > command+=lfile; > } > command+="\n"; > out.write(command.getBytes()); > out.flush(); > > // send a content of lfile - manadan o arquivo > fis=new FileInputStream(lfile); > > byte[] buf=new byte[1024]; > int nLidos; > while((nLidos = fis.read(buf))>=0){ > out.write(buf,0,nLidos); > } > > /* while(true){ > int len=fis.read(buf, 0, buf.length); > if(len<=0) break; > out.write(buf, 0, len); //out.flush(); > > }*/ > fis.close(); > fis=null; > // send '\0' > buf[0]=0; > out.write(buf, 0, 1); > out.flush(); > out.close(); > channel.disconnect(); > session.disconnect(); > > > if(fis!=null) > fis.close(); > > > } > > static int checkAck(InputStream in) throws Exception{ > int b=in.read(); > // b may be 0 for success, > // 1 for error, > // 2 for fatal error, > // -1 > if(b==0) return b; > if(b==-1) return b; > > if(b==1 || b==2){ > StringBuffer sb=new StringBuffer(); > int c; > do { > c=in.read(); > sb.append((char)c); > } > while(c!='\n'); > if(b==1){ // error > System.out.print(sb.toString()); > } > if(b==2){ // fatal error > System.out.print(sb.toString()); > } > } > return b; > } > > public class MyUserInfo implements UserInfo, UIKeyboardInteractive{ > > public String getPassphrase() { > return null; > } > > public String getPassword() { > return senha; > } > > public boolean promptPassword(String string) { > return true; > } > > public boolean promptPassphrase(String string) { > return true; > } > > public boolean promptYesNo(String string) { > return true; > } > > public void showMessage(String string) { > } > > public String[] promptKeyboardInteractive(String string, > String string0, String string1, String[] prompt, boolean[] b) { > String[] response=new String[prompt.length]; > for(int i=0; i<prompt.length; i++){ > response[i]=senha; > } > return response; > > } > > } > > } > > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > JSch-users mailing list > JSc...@li... > https://lists.sourceforge.net/lists/listinfo/jsch-users |