Java中使用FTP协议复制远程文件(使用sendCommand将cp -p复制到Linux) [英] Duplicate remote file over FTP protocol in Java (cp -p to Linux using sendCommand)
问题描述
我正在使用Apache FTPClient
。我是一个文件夹的副本,就像 cp -p
一样,但是来自Java。我怎么能用'sendCommand'方法做到这一点,还是可以用其他任何方式? 重命名
方法移动文件但不保留备份副本。
I m using Apache FTPClient
. I was a do a copy of file in a folder just like cp -p
, but from Java. How can I do that using 'sendCommand' method or will it be possible any other way? The rename
method moves the file but does not keep a backup copy.
推荐答案
没有通过FTP协议复制远程文件的标准方法。有些FTP服务器支持专有或非标准扩展。
There's no standard way to duplicate a remote file over FTP protocol. Some FTP servers support proprietary or non-standard extensions for this though.
因此,如果你很幸运,你的服务器是带有 mod_copy模块,你可以使用 FTP.sendCommand
来发出这两个命令: / p>
So if your are lucky that your server is ProFTPD with mod_copy module, you can use FTP.sendCommand
to issue these two commands:
CPFR sourcepath
CPTO targetpath
第二种可能性是您的服务器允许您执行任意shell命令。这也不常见。如果您的服务器支持此功能,您可以使用 SITE EXEC
命令:
SITE EXEC cp -p sourcepath targetpath
另一个解决方法是打开与FTP服务器的第二个连接,并通过将被动模式数据连接管道连接到活动模式数据连接,使服务器将文件上载到自身。在PHP中实现此解决方案显示在 FTP将文件复制到同一FTP中的另一个位置。
如果这两种情况都不起作用,您所能做的就是将文件下载到本地临时位置并重新上传回目标位置。
If neither of this works, all you can do is to download the file to a local temporary location and re-upload it back to the target location.
另见:
- FTP copy a file to another place in same FTP.
- How to copy a file on the ftp server to a directory on the same server in java?
这篇关于Java中使用FTP协议复制远程文件(使用sendCommand将cp -p复制到Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!