Duplicate remote file over FTP protocol in Java (cp -p to Linux using sendCommand)

冷暖自知 提交于 2019-12-01 12:15:34

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.


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

The second possibility is that your server allows you to execute arbitrary shell commands. This is not common either. If your server supports this you can use SITE EXEC command:

SITE EXEC cp -p sourcepath targetpath

Another workaround is to open a second connection to the FTP server and make the server upload the file to itself by piping a passive mode data connection to an active mode data connection. Implementation of this solution in PHP is shown in FTP copy a file to another place in same 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.

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!