0 votes
ago by (120 points)

Hi there,

We've recently ran into an issue where using backslashes in the path causes SftpPathNotFoundException: Renci.SshNet.Common.SftpPathNotFoundException : Invalid path.

We have some unit tests set up where we spin up the FTP server locally and upload a file successfully with forward slashes. But once we change those to back slashes, the tests break with the above-mentioned exception.

I discovered the AcceptWindowsPaths setting, which I set to true. But nothing changed after setting this to true.

This is a small snippet of our setup:

var fileServer = new FileServer();
fileServer.Settings.AllowedAuthenticationMethods = AuthenticationMethods.Password;
fileServer.Settings.AcceptWindowsPaths = true;

fileServer.Authentication += this.Authenticate;
fileServer.PathAccessAuthorization += this.PathAccessAuthorization;

I would like to know if we did this right, or do we need more configuration? Also, is there an event that we can hook into so we can do the normalization ourselves?

Thank you & kind regards,

Thomas

Applies to: Rebex FTP/SSL

1 Answer

0 votes
ago by (150k points)

Normally, backslashes are not actually supposed to work with SFTP at all, and Rebex File Server's SFTP presents a file system that uses a forward slash ('/') character as a directory separator. This applies even when running on Windows, and it corresponds to SFTP protocol specification.

The AcceptWindowsPaths option is an exception to this, but it is still not supposed to switch the server's file system into 'backslash is a separator' mode. All it does is enable normalization of Windows-like paths on input (as a workaround for a specific instance of misbehaved SFTP client). This means that, for example, if the client sends the "d:\directory\file" path, the server treats it as "/d/directory/file". But if the SFTP client has additional expectations beyond this (for example, if it assumes that responses to SSH_FXP_REALPATH command use paths with backslashes as well), interoperability issues are very likely. But to be able to tell what exactly went wrong, we would have to know which path format was actually used in the request that failed with "Invalid path" error.

ago by (120 points)
Hi Lukas, thanks for your swift reply.

The client who is trying to connect to our server is hosted on a Windows machine. They told us their SFTP client is converting it into a Windows path, something similar to: sftp://sftp.domain.io/path\OUT. (I anonymized our domain).

If possible, we would like to receive this path and normalize it on the server side. However, it seems that Rebex already throws this exception somewhere internally.


Thanks again,

Thomas
ago by (150k points)
Hi Thomas, can you enable [ogging at LogLevel.Verbose (https://www.rebex.net/file-server/features/logging.aspx) at the server, and see which "Resolving path" entries are there in the log when the client receives the "invalid path" error?
...