[英]How in WinSCP .NET assembly read remote file to memory
我必須讀取文件內容或讀取文件字節,並需要將我們的數據庫存儲在其中。
使用 .NET System.IO.File
我們可以簡單地調用File.ReadAllBytes(file)
。
如何在 WinSCP .NET 程序RemoteFileInfo
使用RemoteFileInfo
?
WinSCP .NET 程序集僅在當前測試版 (5.18) 中支持使用Session.GetFile
方法使用流提供遠程文件的內容:
using (Stream stream = session.GetFile("/path/file.ext"))
{
// use the stream
}
使用當前的穩定版本,您只能 將文件下載到本地臨時位置,然后從那里讀取到內存中。
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.