Topic "Downloaded files getting whole remote path name as Filename"

Author Message
wirvanica

Guest


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:
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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26299
Location: Prague, Czechia
You have to use forward slashes in the path to a remote file:

var _ftpFolder = "ftproot/TestFolder/datFiles/Server/";
George A.

Guest


Session.CombinePaths(...) method does not work correctly. Instead use Path.Combine(...), it will format path correctly and handle all slashes..
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26299
Location: Prague, Czechia
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.
_________________
Martin Prikryl
George A.

Guest


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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26299
Location: Prague, Czechia
In WinSCP you have to use backslashes for local path and forward slashes for remote path.
George A.

Guest


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

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License