The Sftp.GetList()
method keeps all the information about all items process in memory, which seems to be over your memory limits.
To solve this issue, handle items on-the-fly one-by-one. It can be done like this:
// register listing handler
client.ListItemReceived += (s, e) =>
{
// process current item
SftpItem item = e.Item;
// ... e.g. Console.WriteLine(item.Name);
// skip adding to resulting collection
e.Ignore();
};
// perform listing
var list = client.GetList();
// the resulting collection contains no items
// due to e.Ignore() call in listing handler
Console.WriteLine(list.Count);
However, please note that by calling ListSFTPFile.Add(objSFTPFile);
you also keep all the information about processed items in memory. This can also cause System.OutOfMemoryException
.