如何使用Java将存储在远程SFTP服务器中的文件复制到同一远程服务器中的另一个文件夹? [英] How do I copy files stored in a remote SFTP server to another folder in the same remote server using Java?

查看:2104
本文介绍了如何使用Java将存储在远程SFTP服务器中的文件复制到同一远程服务器中的另一个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用以下方法将远程服务器中的几个选定文件(执行少量检查后)复制到同一个远程服务器:

I have been trying to copy few selected files (after performing few checks), in a remote server to the same remote server using:

File localFile = new File(srcPath);
sftpChannel.put(localFile.getAbsolutePath(),localFile.getName());

我甚至尝试使用将这些选定的文件复制到本地计算机get()方法。

有人可以帮忙吗?

推荐答案

核心SFTP协议不支持复制远程文件。

A core SFTP protocol does not support duplicating a remote file.

copy-file 协议的扩展名,但是支持只有少数SFTP服务器(例如 ProFTPD / mod_sftp 和Bitvise SFTP服务器) 。

There's draft of copy-file extension to the protocol, but that's supported by only few SFTP servers (ProFTPD/mod_sftp and Bitvise SFTP server for example).

JSch库也不支持 copy-file 扩展名。

The JSch library does not support the copy-file extension either.

替代方案:


  • 如果您有shell访问权限,请打开exec频道,然后使用shell cp 命令(或服务器操作系统的等效命令)。

    参见 Exec.java 示例

  • 否则,您唯一的选择是将文件下载到本地临时位置,并将其副本上载回另一个/目标远程目录。或使用流,以避免临时文件。

  • If you have a shell access, open an "exec" channel, and use shell cp command (or equivalent command for your server's OS).
    See Exec.java example.
  • Otherwise, your only option is to download the file to a local temporary location and upload its copy back to a different/target remote directory. Or use streams, to avoid a temporary file.

另请参阅如何使用SFTP将文件复制/复制到另一个目录?

这篇关于如何使用Java将存储在远程SFTP服务器中的文件复制到同一远程服务器中的另一个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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