paillave / Etl.Net

Mass processing data with a complete ETL for .net developers
https://paillave.github.io/Etl.Net/
MIT License
668 stars 92 forks source link

SFTP connections not working without trailing slashes in folder paths #444

Open pagan-gerbil opened 1 year ago

pagan-gerbil commented 1 year ago

When trying to use the SFTP provider to get files, I ran into a possible bug - the SftpFileValue uses Path.Combine in the GetContent method to pass a filepath to the SFTP server, however if there's no trailing path delimiter ie, Path.Combine("SomeRoot/content", "filename.txt") then Path.Combine assumes the default for the machine it is running on. This can lead to a Linux SFTP server receiving a filepath with mixed forward and back slashes, and Renci.SshNet spits out a 'No such file' exception. That sent me down a lot of wrong turns since I assumed there was something wrong with the SFTP server or the authentication since the file clearly existed.

There is an easy workaround - make sure that there are trailing slashes in the path. It feels like Path.Combine is redundant in the SftpFileValue then because it's just concatenating the strings together at that point, and the error message as it stands is not helpful in trying to track down the issue (especially since the filepath isn't included in the exception, and the bits of path on their own seem sensible when passing them in - indeed, they work to get a list of the files at that location!)

paillave commented 1 year ago

I will try to find a good solution for this, thanks for pointing this out.