[英]How do I copy files stored in a remote SFTP server to another folder in the same remote server using Java?
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());
I have even tried to copy those selected files to my local machine using the get()
method.我什至尝试使用get()
方法将这些选定的文件复制到我的本地计算机。
Can somebody help?有人可以帮忙吗?
A core SFTP protocol does not support duplicating a remote file.核心 SFTP 协议不支持复制远程文件。
There's draft of copy-file
/ copy-data
extensions to the protocol .协议有copy-file
/ copy-data
扩展草案。 But those are supported by only few SFTP servers.但只有少数 SFTP 服务器支持这些。 In the most widespread OpenSSH SFTP server it is supported only by very recent version 9.0 .在最广泛使用的 OpenSSH SFTP 服务器中,只有最近的9.0 版本才支持它。 Other servers are for example ProFTPD mod_sftp
and Bitvise SFTP server.其他服务器例如ProFTPD mod_sftp
和 Bitvise SFTP 服务器。
The JSch library does not support the extensions. JSch 库不支持扩展。
Alternatives:备择方案:
cp
command (or equivalent command for your server's OS).如果您有 shell 访问权限,请打开“exec”通道,并使用 shell cp
命令(或服务器操作系统的等效命令)。Exec.java
example .请参阅Exec.java
示例。See also How can I copy/duplicate a file to another directory using SFTP?另请参阅如何使用 SFTP 将文件复制/复制到另一个目录?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.