Move files to Sftp server

0 votes
asked Sep 24, 2012 by Rebex KB (8,330 points)
edited Nov 15, 2012

How can I move files from the local machine to a SFTP server? I need the original files to be deleted as part of the move operation.

Applies to: Rebex SFTP

1 Answer

+1 vote
answered Sep 24, 2012 by Tomas Knopp (58,890 points)
edited Nov 15, 2012

Hello,

It is easy to move files since the release 2012 R1. Use the Upload method in combination with TransferMethod.Move mode to achieve the move funcionality like this:

        string serverName = "server";
        string userName = "username";
        string password = "password";

        Sftp sftp = new Sftp();
        sftp.Connect(serverName);
        sftp.Login(userName, password);

        // moves the directory data to the SFTP server 'remotePath'
        sftp.Upload(@"C:\data", "/remotePath", 0, TransferMethod.Move, 0 );

        sftp.Disconnect();

This will copy the directory 'data' to SFTP server and delete the local directory 'data'.

commented Nov 15, 2012 by Jan Sotola (16,930 points)
edited Nov 15, 2012

NOTE: if you want to move files from one folder on remote server to another folder on the same server, please see this article.

...