-1

How can I recursively copy a folder from Windows to remote linux server using jsch sftp?

I have already tried using sftpchannel.put(src,dest) but it transfers only files. I also tried iterating over the file list to look for a directory and running a recursive loop but it made the code all the more complicated with additional exception handling. Is their any other way to do this?

Is their any way to use something like rsync between windows and linux machines using Java code?

Sajjad Manal
  • 371
  • 4
  • 25
Faiz Kidwai
  • 463
  • 5
  • 26

1 Answers1

2

Jsch doesn't have an SFTP operation to recursively transfer a directory from local to remote (or from remote to local either). To recursively transfer a directory using Jsch, you will need to write code to construct the list of files and directories to be transferred, then issue ChannelSftp.mkdir() calls to create each remote directory and ChannelSftp.put() operations to transfer each file.

The only way I know of to use rsync from java is to call the rsync command line utility as an external command. It will invoke the ssh command line utility or another external program to make its own connection to the remote server. Jsch wouldn't normally be involved.

Kenster
  • 23,465
  • 21
  • 80
  • 106
  • 1
    It is like when we drag and drop a folder/file through WinSCP.. I want to mimic the same behavior through Java code.. – Faiz Kidwai Sep 22 '16 at 05:16