stream.ReadTimeout'引发了'System.InvalidOperationException'类型的异常

问题描述 投票:2回答:1

我正在尝试从SFTP下载一个zip文件并在内存中解压缩以处理该文件

我正在使用SSH.Net下载文件。

private static void processfilesfromftp(List<TSOracleMicrosDownLoadSetUp> list)
    {
        SftpClient sftp = HelperFunctions.GetClientConnection();
        if(sftp.IsConnected)
        {
            var files = sftp.ListDirectory("/");
            ZipFile zips = new ZipFile();
            string path = string.Empty;
            foreach(var file in files)
            {
                Stream unzippedEntryStream = new MemoryStream();
                path = string.Format("/{0}", file.Name);
                //byte[] arr = sftp.ReadAllBytes(file.FullName);
                var stream = new BufferedStream(sftp.OpenRead(file.FullName));
                //System.IO.TextReader textReader = new System.IO.StreamReader(stream);
                //System.IO.MemoryStream mStream = new MemoryStream();

                using (ZipFile zip = ZipFile.Read(stream))
                {
                    ZipEntry e = zip[0];
                    e.Extract(unzippedEntryStream);
                    System.IO.TextReader textReader = new System.IO.StreamReader(unzippedEntryStream);
                    string data = textReader.ReadToEnd();
                }
            }
        }
    }

内存流抛出错误System.InvalidOperationException异常,位于

var stream = new BufferedStream(sftp.OpenRead(file.FullName));

更新

它没有引发任何错误,但是解压缩文件的最终输出为空。

enter image description here

enter image description here

使用框架4.5.2和Visual Studio 2017

c# acumatica
1个回答
0
投票

这更多是SSH.Net问题,而不是特定的Acumatica。似乎问题与SSH连接有关。

要更改超时,您可以使用SshClient.ConnectionInfo.Timeout。但是您需要捕获异常并优雅地处理它。Here is a post存在类似问题。

顺便说一句,您可以使用随附的Acumatica library to read the zip file

© www.soinside.com 2019 - 2024. All rights reserved.