<tfoot id='L5Kly'></tfoot>

    <i id='L5Kly'><tr id='L5Kly'><dt id='L5Kly'><q id='L5Kly'><span id='L5Kly'><b id='L5Kly'><form id='L5Kly'><ins id='L5Kly'></ins><ul id='L5Kly'></ul><sub id='L5Kly'></sub></form><legend id='L5Kly'></legend><bdo id='L5Kly'><pre id='L5Kly'><center id='L5Kly'></center></pre></bdo></b><th id='L5Kly'></th></span></q></dt></tr></i><div id='L5Kly'><tfoot id='L5Kly'></tfoot><dl id='L5Kly'><fieldset id='L5Kly'></fieldset></dl></div>

      <small id='L5Kly'></small><noframes id='L5Kly'>

          <bdo id='L5Kly'></bdo><ul id='L5Kly'></ul>
        <legend id='L5Kly'><style id='L5Kly'><dir id='L5Kly'><q id='L5Kly'></q></dir></style></legend>
      1. 如何将存储在 FTP 服务器上的 ZIP 文件中的数据导

        时间:2023-06-04

        1. <small id='JC1yt'></small><noframes id='JC1yt'>

            <tbody id='JC1yt'></tbody>
          <i id='JC1yt'><tr id='JC1yt'><dt id='JC1yt'><q id='JC1yt'><span id='JC1yt'><b id='JC1yt'><form id='JC1yt'><ins id='JC1yt'></ins><ul id='JC1yt'></ul><sub id='JC1yt'></sub></form><legend id='JC1yt'></legend><bdo id='JC1yt'><pre id='JC1yt'><center id='JC1yt'></center></pre></bdo></b><th id='JC1yt'></th></span></q></dt></tr></i><div id='JC1yt'><tfoot id='JC1yt'></tfoot><dl id='JC1yt'><fieldset id='JC1yt'></fieldset></dl></div>
        2. <tfoot id='JC1yt'></tfoot>
              <bdo id='JC1yt'></bdo><ul id='JC1yt'></ul>

                <legend id='JC1yt'><style id='JC1yt'><dir id='JC1yt'><q id='JC1yt'></q></dir></style></legend>
                  本文介绍了如何将存储在 FTP 服务器上的 ZIP 文件中的数据导入 C# 中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  此代码从 FTP 服务器导入 void.dat 文件.现在 void.dat 在 archive.zip 文件下.那么如何从数据库中的 archive.zip 中提取和导入数据 void.dat?

                  This code imports the void.dat file from the FTP server. Now void.dat is under archive.zip file. So how can I extract and import data void.dat from the archive.zip in my database?

                  WebClient request = new WebClient();
                  string url = "ftp://agk.com/Files/" + "Void.dat";
                  request.Credentials = new NetworkCredential("user", "password");
                  
                  byte[] newFileData = request.DownloadData(url);
                  string[] lines = System.Text.Encoding.UTF8.GetString(newFileData).Split('
                  ');
                  for (int i = 2; i < lines.Length-1; i++)
                  {
                      int count = lines[i].Split('	').Count();
                  
                          DateTime? Date              = Convert.ToDateTime((lines[i].Split('	')[0]) == null || (lines[i].Split('	')[0]) == "" || (lines[i].Split('	')[0]) == "N" ? (lines[i].Split('	')[2]) = null : (lines[i].Split('	')[0])).Date;
                          string   Time               = ((lines[i].Split('	')[1]) == null || (lines[i].Split('	')[1]) == "" || (lines[i].Split('	')[1]) == "N" ? (lines[i].Split('	')[1]) = null : (lines[i].Split('	')[1]));
                          int      Shift              = Convert.ToInt32((lines[i].Split('	')[2]) == null || (lines[i].Split('	')[2]) == "" || (lines[i].Split('	')[2]) == "N" ? (lines[i].Split('	')[2]) = null : (lines[i].Split('	')[2]));
                          int      EmployeeID         = Convert.ToInt32((lines[i].Split('	')[3]) == null || (lines[i].Split('	')[3]) == "" || (lines[i].Split('	')[3]) == "N" ? (lines[i].Split('	')[3]) = null : (lines[i].Split('	')[3]));
                          double   Amount             = Convert.ToDouble((lines[i].Split('	')[4]) == null || (lines[i].Split('	')[4]) == ""|| (lines[i].Split('	')[4]) == "N" ? (lines[i].Split('	')[4]) = null : (lines[i].Split('	')[4]));
                          double   Items              = Convert.ToDouble((lines[i].Split('	')[5]) == null || (lines[i].Split('	')[5]) == "" || (lines[i].Split('	')[5]) == "N" ? (lines[i].Split('	')[5]) = null : (lines[i].Split('	')[5]));
                          int      DrawerOpen         = Convert.ToInt32((lines[i].Split('	')[6]) == null || (lines[i].Split('	')[6]) == "" || (lines[i].Split('	')[6]) == "N" ? (lines[i].Split('	')[6]) = null : (lines[i].Split('	')[6]));
                          int      Postpone           = Convert.ToInt32((lines[i].Split('	')[7]) == null || (lines[i].Split('	')[7]) == "" || (lines[i].Split('	')[7]) == "N" ? (lines[i].Split('	')[7]) = null : (lines[i].Split('	')[7]));
                          int      LocationID         = Convert.ToInt32((lines[i].Split('	')[8]) == null || (lines[i].Split('	')[8]) == "" || (lines[i].Split('	')[8]) == "N" ? (lines[i].Split('	')[8]) = null : (lines[i].Split('	')[8]));
                          
                          _context.Database.ExecuteSqlCommand(@"Insert into VOIDS (Date,Time,Shift,EmployeeID,Amount,Items,DrawerOpen,Postpone,LocationID)
                      Values({0},{1},{2},{3},{4},{5},{6},{7},{8})", Date, Time, Shift, EmployeeID, Amount, Items, DrawerOpen, Postpone, LocationID);
                          _context.SaveChanges();
                      
                  }
                  return "Successful Import";
                  

                  推荐答案

                  要从 FTP 服务器上 ZIP 存档中的文件中读取字符串内容,请使用:

                  To read a string contents from a file located in a ZIP archive on FTP server, use:

                  var request = WebRequest.Create("ftp://ftp.example.com/remote/path/archive.zip");
                  request.Credentials = new NetworkCredential("username", "password");
                  request.Method = WebRequestMethods.Ftp.DownloadFile;
                  
                  string data;
                  using (Stream ftpStream = request.GetResponse().GetResponseStream())
                  using (var archive = new ZipArchive(ftpStream, ZipArchiveMode.Read))
                  {
                      using (Stream entryStream = archive.GetEntry("void.dat").Open())
                      using (var reader = new StreamReader(entryStream, Encoding.UTF8))
                      {
                          data = reader.ReadToEnd();
                      }
                  }
                  
                  string[] lines = data.Split('
                  ');
                  // rest of your code
                  


                  无论如何,当您将字符串拆分为行时,更有效的方法是直接按行读取流:


                  As you split the string into lines anyway, more efficient would be to read the stream directly by lines:

                      using (var reader = new StreamReader(entryStream, Encoding.UTF8))
                      {
                          string line;
                          int i = 0;
                          while ((line = reader.ReadLine()) != null)
                          {
                              // skip the first two lines, as your original code does
                              if (i >= 2)
                              {
                                  int count = line.Split('	').Count();
                  
                                  // rest of your code for parsing individual lines
                                  // (with 'lines[i]' replaced with 'line')
                              }
                              i++;
                          }
                      }
                  


                  请注意,代码会下载整个存档,即使它最终只从存档中读取一个特定文件.

                  您关于相反操作的相关问题:
                  如何在C#中上传zip和上传字符串数据到FTP服务器

                  这篇关于如何将存储在 FTP 服务器上的 ZIP 文件中的数据导入 C# 中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:上传到 FTP 时保留图像创建日期 下一篇:用 C# 编写的 FTP 服务器

                  相关文章

                  最新文章

                  <i id='J2HFi'><tr id='J2HFi'><dt id='J2HFi'><q id='J2HFi'><span id='J2HFi'><b id='J2HFi'><form id='J2HFi'><ins id='J2HFi'></ins><ul id='J2HFi'></ul><sub id='J2HFi'></sub></form><legend id='J2HFi'></legend><bdo id='J2HFi'><pre id='J2HFi'><center id='J2HFi'></center></pre></bdo></b><th id='J2HFi'></th></span></q></dt></tr></i><div id='J2HFi'><tfoot id='J2HFi'></tfoot><dl id='J2HFi'><fieldset id='J2HFi'></fieldset></dl></div>
                • <legend id='J2HFi'><style id='J2HFi'><dir id='J2HFi'><q id='J2HFi'></q></dir></style></legend>
                • <tfoot id='J2HFi'></tfoot>

                    <small id='J2HFi'></small><noframes id='J2HFi'>

                    • <bdo id='J2HFi'></bdo><ul id='J2HFi'></ul>