0 votes
by (2.0k points)

Hello.

I am asking a question because of a problem with repeated folder searches in SFTP.
I don't know the exact terminology for this problem, so the explanation is a bit complicated.

When connecting to the Ubuntu server via SFTP, the "/usr/bin/X11" folder became a problem.

In the /usr/bin folder, the X11 folder is linked with ".". (Pointing to your own folder.)

Therefore, when I enter the /usr/bin/X11 folder, there is X11 folder and it goes into the /usr/bin/X11/X11 folder.
Continuing to go in like this is problematic.

When I call ResolveSymlink("/usr/bin/X11") I get "." is returned.
It would be nice if the absolute path was returned, but it only returns Link information.

Is there any SFTP option or command that solves this?

If I can get the actual absolute path like Unix's realpath command,
If it is a link and the actual absolute path is the parent of the requested file/folder, the folder will be hidden or processed as a regular file.

If there is a better way, please let me know.

I have the same problem with FTP, so I would be very grateful if you could tell me how to handle it with FTP.

Thank you
Sincerely.

Applies to: Rebex SFTP

1 Answer

+1 vote
by (73.6k points)
selected by
 
Best answer

In the SFTP protocol, the client can request realpath command. Unfortunately, we do not have public API for it currently. We will think about adding it in a future version.

However, in the FTP protocol there is no possibility to request realpath command. The FTP server can include symlink target in the response to LIST or MLSD commands. The info provided is equivalent to ResolveSymlink() method in the SFTP.

I suggest this solution for both protocols:

  • List content of a directory.
  • For symlinks: get the linkTarget using Sftp.ResolveSymlink() or FtpItem.SymlinkPath.
  • If linkTarget equals to "." or ".." skip that symlink.

    • Depending on your needs also skip symlink if linkTarget starts with "./" or "../" prefix.

This should cover your current scenario and possibly some future scenarios. If you encounter a situation where this solution is not enough, please let us know.


Note: Some FTP servers do not include symlink info in the MLSD command. For such servers disable MLSD like this:

ftp.EnabledExtensions &= ~FtpExtensions.MachineProcessingList;
by (2.0k points)
I hope to support realpath functionality.
Thank you.
...