Topic "C# FTP download symlinked file"

Author Message
CphChrIsThisNameAllowed

Guest


Hi.

I'm having trouble downloading a file from IMDb's alternative interfaces FTP, which seems to have symlinks for files.
The error returned:

Code:

Error transferring file '/pub/mirrors/ftp.imdb.com/pub/aka-titles.list.gz'.
Real path and requested remote path do not match: "/.m/mirrors1l/ftp.imdb.com/pub/"  "/pub/mirrors/ftp.imdb.com/pub/"
Copying files from remote side failed.


Searching through this forum, there are old posts from 2002 stating that symlinks are not supported, and then more recent posts, pointing to: https://winscp.net/eng/docs/rawsettings and
Code:
FollowDirectorySymlinks


Tried adding the rawsettings, but to no avail:

Code:

try
{
   var sessionOptions = new SessionOptions
   {
      Protocol = Protocol.Ftp
   };

   sessionOptions.ParseUrl("ftp://anon:anon@ftp.funet.fi/");
   sessionOptions.AddRawSettings("ResolveSymlinks", "1");
   sessionOptions.AddRawSettings("FollowDirectorySymlinks", "1");

   using (Session session = new Session())
   {
      session.FileTransferProgress += progressHandler;

      session.Open(sessionOptions);

      TransferOptions transferOptions = new TransferOptions();
      transferOptions.TransferMode = TransferMode.Binary;

      var transferResult = session.GetFiles(
         "/pub/mirrors/ftp.imdb.com/pub/aka-titles.list.gz",
         "c:\SomeFolder\aka-titles.list.gz",
         false,
         transferOptions);

      transferResult.Check();
   }
}
catch (Exception e)
{
   Debug.WriteLine("Error: {0}", e);
}


Tried to see if I could get the translated symlink using EnumerateRemoteFiles or ListDirectory, but the file's FullName is still the symlinked path.
The only option I have so far, is to catch the exception, parse the Message to get the real path and make a second call to GetFiles(), which is as hacky as it gets.

Any pointers would be much appreciated.

/Chris
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25946
Location: Prague, Czechia
So did you try using the actual path, instead of the path to the symlink?
CphChrIsThisNameAllowed

Guest


martin wrote:
So did you try using the actual path, instead of the path to the symlink?


Yes, here's how I get around it:

Code:

// Can't get symlink to work even with rawsetting, so executing this to get the real link
var commandResult = session.ExecuteCommand($"CWD {remotePath}");
//250 OK. Current directory is /.m/mirrors1l/ftp.imdb.com/pub
var pathToRemoteFile = $"{commandResult.Output.Replace("250 OK. Current directory is ", "")}/{remoteFileName}";


But would have liked a cleaner way, than the above.
Remember, that I can't just hardcode the current symlinked path, as this may change (and most likely will, as it looks like a load-balanced link).

/Chris
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25946
Location: Prague, Czechia
This change should help you:
https://winscp.net/tracker/show_bug.cgi?id=1518

Can you send me an email, so I can send you back a development version of WinSCP? Please include link back to this topic in your email. Also note in this topic that you have sent the email. Thanks.

You will find my address (if you log in) in my forum profile.
CphChrIsThisNameAllowed

Guest


martin wrote:
This change should help you:
https://winscp.net/tracker/show_bug.cgi?id=1518

Can you send me an email, so I can send you back a development version of WinSCP? Please include link back to this topic in your email. Also note in this topic that you have sent the email. Thanks.

You will find my address (if you log in) in my forum profile.


Martin, it's much appreciated, the time you take for post like this.

I think it would be faster if you spin up a dev-version of WinSCP yourself, and use the code posted in the first post.
I can live with my workaround, as this is just a hobby project.
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