I am creating an SFTP upload program. It is working great, it connects to the remote SFTP server and uploads the files as intended. The issue I am having it I want the files once uploaded moved to a new directory on the local server. I have searched WinSCP site and did google searches, but the code I am up with it not working. Here is what I have:
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
session.MoveFile(transfer.FileName, Local_Processed);
}
In the log it states that it is moving the files but the files remain in the original folder and nothing appears in the processed folder.
The Session.MoveFile
is for moving a remote file to another remote directory or for renaming a remote file. It's not for moving a remote file to a local directory.
To move a remote file to a local directory, use the remove
parameter of the Session.GetFiles
.
Though for me it looks like you actually want to move an original local file (that was uploaded) to another local directory. So it has actually nothing to do with WinSCP.
To move a local file, use the File.Move
:
File.Move(transfer.FileName, destinationPath);