Tuesday, February 11, 2014

scp protocol using jsch

Using Jsch to  scp a file to a remote computer I found Jan Pechanec's excellent blog how_the_scp_protocol_works . The one thing I couldn't figure out was how to specify the remote directory. 

Originally I tried using D mode dir to specify the directory. That results in an error.

As you can specify the target directory using scp manually there must have been a way. Turns out it is simple.

Line 43 of scp is String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile; 

All that is required is to specify the target dir in the command as follows:

String command="scp " + (ptimestamp ? "-p" :"") +" -t "+targetDir+'/'+rfile;

No comments: