I am downloading from SFTP and want to check if the file exists in the folder "directory @"D:..." or not
using (SftpClient sftp = new SftpClient(Host, Port, Username, Password))
{
sftp.Connect();
var files = sftp.ListDirectory(RemoteFileName);
string downloadFileNames = string.Empty;
foreach (var file in files)
{
if (file.FullName.EndsWith(".gz"))
{
using (Stream fileStream = File.Create(Path.Combine(directory, file.Name)))
{
sftp.DownloadFile(file.FullName, fileStream);
}
}
downloadFileNames += file.Name;
}
}