使用jsch将远程服务器中的目录移动到同一远程服务器中的另一个位置 [英] Move a directory in remote server to another location in the same remote server using jsch

查看:451
本文介绍了使用jsch将远程服务器中的目录移动到同一远程服务器中的另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSCH API通过sftp连接到远程服务器。
我需要将远程服务器中存在的目录从位置A移动到位置B.
看起来方法 channelsftp.put(src,dest)只允许移动一个文件,而不是目录。

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?

推荐答案

您可以使用rename命令,它会移动文件或目录并将其从原始位置删除。

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

sftpChannel.rename(oldFile, newFile);

sftpChannel.rename(oldFile, newFile);

如果你想保留原始目录/文件,请不要使用这种方法。

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

希望这会有所帮助。

这篇关于使用jsch将远程服务器中的目录移动到同一远程服务器中的另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆