簡體   English   中英

WinSCP .NET 程序集中如何將遠程文件讀取到內存

[英]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);
    }
}

類似問題:使用 WinSCP .NET 程序集以流形式訪問遠程文件內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM