Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

George A.

As a user of WinSCP I should probably expect exception or at least warning generated by API that slash I used is incorrect one, and definitely not writing file with unexpected name in unexpected place...
And as a good practice the software should be able to fix this things in pathings.
Thank you.
George A.

8)
martin

Re: Path.Combine VS session.CombinePaths

In WinSCP you have to use backslashes for local path and forward slashes for remote path.
George A.

Path.Combine VS session.CombinePaths

Path.Combine adds left slash "\" if there is no one. If there is ANY slash this function does not add anything.
Examples:
Path.Combine("D:/data","name.txt") => "D:/data\name.txt"
Path.Combine("D:/data/","name.txt") => "D:/data/name.txt"
Path.Combine("D:\data\","name.txt") => "D:\data\name.txt"


session.CombinePaths adds right slash "/" when there is already left slash "\" slash.
Examples:
session.CombinePaths("D:/data","name.txt") => "D:/data/name.txt"
session.CombinePaths("D:/data/","name.txt") => "D:/data/name.txt"
session.CombinePaths("D:\data\","name.txt") => "D:\data\/name.txt" => creates file: "D:\data%2Fname.txt"

Windows can accept either slash, even they can be mixed in one path. (are we working on windows?)

While working on these examples I discovered another situation with Session.GetFiles:
Session.GetFiles("/folder/name.txt","D:\data\target/name.txt") downloads and creates file in "D:\target\data%2Fname.txt" (this is not where I expected it to be created - "D:\target\data\name.txt")
Session.GetFiles("/folder/name.txt","D:/data/target/name.txt") downloads and creates file in "D:%2Fdata%2Ftarget%2Fname.txt" (this is not where I expected it to be created - "D:\target\data\name.txt")
martin

Re: CombinePaths(...) doesnot work correctly. instead use Path.Combine(...)

George A. wrote:

Session.CombinePaths(...) method does not work correctly. Instead use Path.Combine(...), it will format path correctly and handle all slashes..

Why it does not work correctly?
You cannot use the Path.Combine for a remote path, as the Path.Combine merges the paths with backslashes, while the remote path must use slashes.
George A.

CombinePaths(...) doesnot work correctly. instead use Path.Combine(...)

Session.CombinePaths(...) method does not work correctly. Instead use Path.Combine(...), it will format path correctly and handle all slashes..
martin

Re: Downloaded files getting whole remote path name as Filename

You have to use forward slashes in the path to a remote file:

var _ftpFolder = "ftproot/TestFolder/datFiles/Server/";
wirvanica

Downloaded files getting whole remote path name as Filename

Hi,
I'm downloading from the following folder at my remote path:


ftproot\TestFolder\datFiles\Server\

Trying to download the following file: File123.dat

The files are downloading into my test folder fine, but their name, instead of File123.dat is

ftproot%5CTestFolder%5CdateFiles%5CServer%5CFile123.dat


Code:
            

var _ftpFolder = "ftproot\TestFolder\datFiles\Server\";
var fileName = "File123.dat";
var localFilePath = "C:/test";
var transferResult = _session.GetFiles(_ftpFolder + filename, localFilePath, false);


Any ideas?