Re: How to move file using winSCP when file exist?
Yes than you.
My answer to your question on stackoverflow.com:
If you are asking if WinSCP can do this automatically for you, the answer is "no".
You need to explicitly check target file existence and rename it before you move the file.
Note that rename and move is the same operation from WinSCP .NET Assembly API perspective. So you useSession.MoveFile
method for both:
https://winscp.net/eng/docs/library_session_movefile
From your question, it's not clear ifserver.DoneFilePath
is path to target directory (ending with slash/
) or part to target file (ending with file name). Assuming is is path to target directory only:
string doneFile = server.DoneFilePath + fileInfo.Name;
if (session.FileExists(doneFile))
{
session.MoveFile(doneFile, doneFile + ".bak");
}
// carry on with your move code:
session.MoveFile(server.RemoteDownloadPath + fileInfo.Name, server.DoneFilePath);
https://stackoverflow.com/q/21300315/850848