Hi, this seems to be the root of the issue:
The GetFile should find the file irrespective of the casing.
That is not actually how the method behaves. The GetFile
method just takes whatever path it has been called with, and asks the server to retrieve a file from that particular path. So in practice, SFTP servers running on Unix-like systems are case-sensitive, while SFTP servers running on Windows are case-insensitive.
To achieve the behavior you prefer, you would first have to 'resolve' the supplied file path into a form recognized by the server. To do this, you would have to iterate through all files in the directory to find out if there is a case-insensitive match, and retrieve the 'canonical' name this way. For example:
// connect to the server
var sftp = new Sftp();
sftp.Connect("test.rebex.net");
sftp.Login("demo", "password");
// input path and file name
string path = "/pub/example";
string myFileName = "README.txt";
// try matching the supplied file name to an actual file name at the SFTP server
string fileName = myFileName;
foreach (string actualFileName in sftp.GetNameList(path))
{
if (myFileName.Equals(actualFileName, StringComparison.CurrentCultureIgnoreCase))
{
// use the actual file name instead of input file name
fileName = actualFileName;
break;
}
}
// download the file
sftp.GetFile(path + "/" + fileName, myFileName);
However, watch out for culture-related issues when comparing those strings. For example, for most users, "I" and "i" represent different casings of the same letter. But for a Turkish user, it's different: "I" is an uppercase of "ı", while "İ" is an uppercase of "i". Depending on your scenario, using InvariantCultureIgnoreCase instead of CurrentCultureIgnoreCase migth be a better option, as it produces consistent results.