I am working on a project where I am using WinSCP .NET component for accessing an SFTP host. The functionality of the code is to navigate to a folder in the SFTP and checks whether the provided file name is located inside the folder.
I have the below code and everything is working fine. The below code is checking whether the folder exists in the SFTP remote path. If it's there I am iterating through all the files in the sFTP directory to check whether it has the filename that I provided.
string FolderName = row["Folder_Name"].ToString();
string FileName = row["File_Name"].ToString();
FileName = FileName.Replace("\r\n", string.Empty);
string remotePath = HomeDirectory + FolderName + "/";
if(session.FileExists(remotePath))
{
RemoteDirectoryInfo directory = session.ListDirectory(remotePath);
sFTPFiles.AddRange(directory.Files
.Where(fileInfo => !fileInfo.IsDirectory)
.Select(fileInfo => fileInfo.Name.ToString()));
if(CheckFileExists(FileName, sFTPFiles) != FileExistence.EXISTS)
{
isDiscrepancy = true;
} else
{
row["sftp_available"] = true;
row["discrepancy_on_sftp"] = false;
}
}
The problem that I am facing is the folder name case sensitive issues. In my database the folder names are stored in Upper case. But in the SFTP the same folder names has different case sensitive name ie. Upper Case or Sentence case or Lower Case. Something like folderNAME
, FOLDERNAME
, foldername
, fOLDERNAME
When the if(session.FileExists(remotepath)
is getting executed, it gets failed due to the case sensitive issue. When my Foldername that I am verifying is FOLDERNAME
and the same in SFTP is written as FOLDERname
it is getting skipped due to case sensitivity.
Hence can anyone let me know how to check the folder names with non case sensitive method using WinSCP and C#. All I need is if my Foldername
in my database is FOLDERNAME
, I want to navigate inside that folder in SFTP even though it is in any of the mentioned formats.
Thanks in advance for your help.