JAVA JSCH SFTP programming approach

82 Views Asked by At

I'd like to know which is the best approach in coding an SFTP push and pull method on JAVA.

Initial design was to connect to the remote server, upload / download a single file then disconnect. Repeating the same process for nth time depending on the available file(s) for processing ensuring that any file(s) that may not be transferred will still be reprocessed on the next execution.

Or connect to the remote server, iterate the list of file(s) for upload / download then disconnect after all file(s) are transferred.

Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

Definitely connect once and iterate through a list of stuff to get/put.

Otherwise, for each file you have to go through the encryption handshake process.

Just did a quick test, made a 10mb file out of zeros, then copied it, then scp'd the copies to a vm on my own computer, with a passwordless ssh key.

Copied 7 files - one at a time, and once using a blob

for i in 1 2 3 4 5 6 7
do
  scp zerofile-$i debian@tomcat:~/
done

Took 2.411 seconds according to the time utility.

scp zerofile-* debian@tomcat:/tmp

took 1.432 seconds.