我必须读取文件内容或读取文件字节,并需要在其中存储我们的数据库。
使用.NET System.IO.File
我们可以简单地调用File.ReadAllBytes(file)
。
如何使用RemoteFileInfo
在WinSCP .NET程序集中执行此操作?
WinSCP .NET assembly不支持将远程文件内容“下载”到内存中。
您所能做的就是将download the file带到当地的临时位置,然后从那里读取内存。
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
string localPath = Path.GetTempFileName();
try
{
// Download to a temporary folder
session.GetFiles(remotePath, localPath).Check();
// Read the file contents
byte[] contents = File.ReadAllBytes(localPath);
}
finally
{
// Delete the temporary file
File.Delete(localPath);
}
}
在WinSCP跟踪器中有Stream interface in .NET assembly的请求。