Thanks a lot. The code works fine, but at the end it hangs after the while loop, just before channel.disconnect(), so i thought may be out.close() needs to be done, before channel.disconnect(), after i tried that, out.close() keeps hanging.
The file that is created /tmp/foo.tgz, but if i do local command tar xvf- /tmp/foo.gz, that local command also keeps hanging and not coming back. Can you please let me know what needs to be done to avoid that hanging. Also, I have one more question unrelated to this topic, if i want to transfer two concurrent files at the same time, do i have to open two connections, or just one connection and use two channels ? thanks. Viji Atsuhiko Yamanaka wrote: > Hi, > > +-From: Vijaya Natarajan <v...@hpcrd.lbl.gov> -- > |_Date: Tue, 09 Aug 2011 14:58:14 -0700 __ > | > |I am following the suggestions given in this reply to use > |tar -c -f -z folder to speed up the download transfers. > |I tried it in my program, it is said just send the output to std output > |and later piped and save it in a file. > |Is there any example to show how to do that. I would really appreciate > that. > > Suppose that if you want to do following ssh command operations in JSch APIs, > $ ssh f...@example.com "(cd /usr; tar czf - src)" > /tmp/foo.tgz > how about following chunk of code? > > Channel channel=session.openChannel("exec"); > > String command="(cd /usr; tar czf - src)"; > ((ChannelExec)channel).setCommand(command); > > java.io.FileOutputStream out = new > java.io.FileOutputStream("/tmp/foo.tgz"); > channel.setOutputStream(out); > channel.setInputStream(null); > ((ChannelExec)channel).setErrStream(System.err); > > channel.connect(); > > while(true){ > if(channel.isClosed()){ > System.out.println("exit-status: "+channel.getExitStatus()); > break; > } > try{Thread.sleep(1000);}catch(Exception ee){} > } > channel.disconnect(); > > out.close(); > > > Sincerely, > -- > Atsuhiko Yamanaka > JCraft,Inc. > 1-14-20 HONCHO AOBA-KU, > SENDAI, MIYAGI 980-0014 Japan. > Tel +81-22-723-2150 > +1-415-578-3454 > Skype callto://jcraft/ > Twitter: http://twitter.com/ymnk > Facebook: http://facebook.com/aymnk > > ------------------------------------------------------------------------------ > uberSVN's rich system and user administration capabilities and model > configuration take the hassle out of deploying and managing Subversion and > the tools developers use with it. Learn more about uberSVN and get a free > download at: http://p.sf.net/sfu/wandisco-dev2dev > _______________________________________________ > JSch-users mailing list > JSch-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jsch-users > ------------------------------------------------------------------------------ uberSVN's rich system and user administration capabilities and model configuration take the hassle out of deploying and managing Subversion and the tools developers use with it. Learn more about uberSVN and get a free download at: http://p.sf.net/sfu/wandisco-dev2dev _______________________________________________ JSch-users mailing list JSch-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jsch-users