java ftp 复制文件命令,Java中使用FTP协议复制远程文件(使用sendCommand将cp -p复制到Linux)...

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.

解决方案

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值