Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading