【发布时间】:2016-02-10 10:30:49
【问题描述】:
我必须读取文件内容或读取文件字节并且需要将其存储在我们的数据库中。
使用 .NET System.IO.File 我们可以简单地调用File.ReadAllBytes(file)。
如何在 WinSCP .NET 程序集中使用RemoteFileInfo?
【问题讨论】:
标签: .net winscp winscp-net
我必须读取文件内容或读取文件字节并且需要将其存储在我们的数据库中。
使用 .NET System.IO.File 我们可以简单地调用File.ReadAllBytes(file)。
如何在 WinSCP .NET 程序集中使用RemoteFileInfo?
【问题讨论】:
标签: .net winscp winscp-net
WinSCP .NET 程序集仅在当前 beta 版本 (5.18) 中支持使用流提供远程文件的内容,使用 Session.GetFile method:
using (Stream stream = session.GetFile("/path/file.ext"))
{
// use the stream
}
使用当前的稳定版本,您只能将download the file 到本地临时位置并从那里将其读取到内存中。
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Download to a temporary folder
var transfer = session.GetFileToDirectory(remotePath, Path.GetTempPath());
try
{
// Read the file contents
byte[] contents = File.ReadAllBytes(transfer.Destination);
}
finally
{
// Delete the temporary file
File.Delete(transfer.Destination);
}
}
类似问题:Access remote file contents as a stream using WinSCP .NET assembly
【讨论】: