5

I am using JSCH API to connect to remote server through sftp. I need to move a directory present in the remote server from location A to location B. It looks like the method channelsftp.put(src,dest) allows to move only a file and not the directory.

Can someone please explain me how to do this?

Michael Maze
  • 73
  • 2
  • 10

1 Answers1

13

You can use the rename command, it would move the file or directory and delete it from the original place.

sftpChannel.rename(oldFile, newFile);

Don't use this method, if you want to keep the original directory/file.

Hope this helps.

Abs
  • 458
  • 1
  • 7
  • 17
  • to avoid errors, first check that the file oldFile doesn't exist in newFile: sftpChannel.rm(newFile) and then sftpChannel.rename(oldFile, newFile); – sjdms265 Jan 26 '17 at 21:54