如何在WinSCP .NET程序集中将远程文件读取到内存中

时间:2016-02-10 10:30:49

标签: .net winscp winscp-net

我必须读取文件内容或读取文件字节,并且需要在其中存储我们的数据库。

使用.NET System.IO.File,我们只需调用File.ReadAllBytes(file)

如何使用RemoteFileInfo在WinSCP .NET程序集中执行此操作?

1 个答案:

答案 0 :(得分:2)

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请求。

相关问题