Duplicating files from one directory to another on SFTP server using WINSCP and C#

Advertisements

I’m trying to duplicate files from one directory to another using WINSCP while using Session.DuplicateFile. It is duplicating file but instead of provided path, it is saving file on the root directory.

For example.

session.DuplicateFile('/\Susen Test Folder\Uploads\Folder1\Folder2/20190718les155004.png',"\Susen Test Folder\Uploads\Websites\content.folder.co\Folder1\Folder2\20190718les155004.png")

This code is saving file as Susen Test FolderUploadsWebsitescontent.folder.coFolder1Folder220190718les155006.png

on root directory of SFTP server instead of provided path. You can see that filename has changed by removing slashes.

>Solution :

The SFTP protocol (as well as WinSCP API) always uses forward slashes. You are strangely mixing forward and backward slashes.

It should (most likely) be:

session.DuplicateFile(
    "/Susen Test Folder/Uploads/Folder1/Folder2/20190718les155004.png",
    "/Susen Test Folder/Uploads/Websites/content.folder.co/Folder1/Folder2/20190718les155004.png");

Leave a ReplyCancel reply