简体   繁体   English

使用jsch将远程服务器中的目录移动到同一远程服务器中的另一个位置

[英]Move a directory in remote server to another location in the same remote server using jsch

I am using JSCH API to connect to remote server through sftp. 我正在使用JSCH API通过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. 我需要将远程服务器中存在的目录从位置A移动到位置B.看起来方法channelsftp.put(src,dest)只允许移动文件而不是目录。

Can someone please explain me how to do this? 有人可以解释一下如何做到这一点?

You can use the rename command, it would move the file or directory and delete it from the original place. 您可以使用rename命令,它将移动文件或目录并将其从原始位置删除。

sftpChannel.rename(oldFile, newFile); sftpChannel.rename(oldFile,newFile);

Don't use this method, if you want to keep the original directory/file. 如果要保留原始目录/文件,请不要使用此方法。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM