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.
Can somebody help?
A core SFTP protocol does not support duplicating a remote file.
There's draft of copy-file
/ copy-data
extensions to the protocol . But those are supported by only few SFTP servers. In the most widespread OpenSSH SFTP server it is supported only by very recent version 9.0 . Other servers are for example ProFTPD mod_sftp
and Bitvise SFTP server.
The JSch library does not support the extensions.
Alternatives:
cp
command (or equivalent command for your server's OS).Exec.java
example .See also How can I copy/duplicate a file to another directory using SFTP?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.