Downloaded files getting whole remote path name as Filename

Advertisement

wirvanica
Guest

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?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

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/";

Reply with quote

George A.
Guest

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..

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

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.

Reply with quote

George A.
Guest

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")

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Path.Combine VS session.CombinePaths

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

Reply with quote

George A.
Guest

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.

Reply with quote

Advertisement

You can post new topics in this forum