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

CphChrIsThisNameAllowed

Re: C# FTP download symlinked file

martin wrote:

This change should help you:
https://winscp.net/tracker/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.
martin

Re: C# FTP download symlinked file

This change should help you:
https://winscp.net/tracker/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

Re: C# FTP download symlinked file

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:

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

Re: C# FTP download symlinked file

So did you try using the actual path, instead of the path to the symlink?
CphChrIsThisNameAllowed

C# FTP download symlinked file

Hi.

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

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
FollowDirectorySymlinks


Tried adding the rawsettings, but to no avail:

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