Copy a file to new location on same server with SFTP

0 votes
asked Jun 28, 2011 by dmilor (160 points)
edited Jun 28, 2011


I need to copy (not move) a file from one location on an SFTP server to another location on the same SFTP server. I found this answer for the FTP component but the SFTP component does not have the CopyToAnotherServer method. How would I achieve this?

EDIT: Answered in 7 minutes - thanks Lukas!

Applies to: Rebex SFTP

1 Answer

+1 vote
answered Jun 28, 2011 by Lukas Pokorny (124,970 points)
edited Jun 28, 2011
Best answer

Unfortunately, the SFTP protocol doesn't have a "copy" command and it doesn't even support server-to-server transfers, which could be used with FTP to achieve this.

However, SFTP runs over an SSH channel, which means it might be possible to take advantage of SSH remote exec functionality to execute commands at the server. This way, you might be able to execute commands such as "cp sourcepath targetpath" (on Unix-based servers) or "copy soucepath targetpath" (on Windows-based servers) to achieve what you need. Please check out the answer to Remote copy file - SFTP for sample code.