简体   繁体   English

如何使用 Java 将存储在远程 SFTP 服务器中的文件复制到同一远程服务器中的另一个文件夹?

[英]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:备择方案:

  • If you have a shell access, open an "exec" channel, and use shell cp command (or equivalent command for your server's OS).如果您有 shell 访问权限,请打开“exec”通道,并使用 shell cp命令(或服务器操作系统的等效命令)。
    See Exec.java example .请参阅Exec.java示例
  • 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.使用流,以避免临时文件。

See also How can I copy/duplicate a file to another directory using SFTP?另请参阅如何使用 SFTP 将文件复制/复制到另一个目录?

暂无
暂无

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

相关问题 如何使用Java Config将提供文件名的文件从一个文件夹移动到远程sftp服务器上的另一个文件夹? - How to move file from one folder to another folder on remote sftp server providing the filename dynamically using Java Config? PHP / Java:如何将文件从一个文件夹复制到远程服务器内的另一个文件夹 - PHP/Java: How to copy the file from one folder into another folder inside the remote server 在Java中使用SFTP将目录复制到远程计算机 - Copy directory to a remote machine using SFTP in java 使用Java从远程服务器下载文件夹 - Downloading the folder from remote server using Java 当使用 Spring 引导 Java 启动 SFTP 远程服务器时如何获得通知? - How to get notified when SFTP Remote Server is UP using Spring Boot Java? 将文件上传到远程服务器后,如何使用Java删除目录? - How to delete directory using java after uploading files to Remote Server? 如何在远程dicom服务器中推送压缩的CT文件? - How do i push compressed CT files in remote dicom server? Spring Integration Java DSL SFTP如何在处理程序中获取远程SFTP服务器信息 - Spring Integration Java DSL SFTP how to get remote SFTP server information in handler 使用Java从远程服务器复制具有特定扩展名的所有文件 - Copy all files with specific extension from remote server with Java 将SFTP文件直接下载到远程服务器文件夹(而不是共享路径) - Download SFTP file to Remote server folder directly (not to shared path)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM