您可以尝试以下代码,该代码在服务器上打开文件并将其读回流中:
using (var sftp = new SftpClient(sFTPServer, sFTPUsername, sFTPPassword))
{
sftp.Connect();
// Load remote file into a stream
var remoteFileStream = sftp.OpenRead("file.txt");
System.IO.TextReader textReader = new System.IO.StreamReader(remoteFileStream);
string s = textReader.ReadToEnd();
sftp.Disconnect()
}