<tfoot id='EYEJL'></tfoot>

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

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

        将通过 HTTP 上传到 ASP.NET 的文件上传到 C# 中的

        时间:2023-06-04

          <legend id='KY7ZR'><style id='KY7ZR'><dir id='KY7ZR'><q id='KY7ZR'></q></dir></style></legend>

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

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

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

                  <tbody id='KY7ZR'></tbody>

                <tfoot id='KY7ZR'></tfoot>
                  本文介绍了将通过 HTTP 上传到 ASP.NET 的文件上传到 C# 中的 FTP 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  上传表格:

                  <form asp-action="Upload" asp-controller="Uploads" enctype="multipart/form-data">
                  <input type="file" name="file" maxlength="64" />
                  <button type="submit">Upload</button>
                  

                  控制器/文件上传:

                  public void Upload(IFormFile file){
                      using (WebClient client = new WebClient())
                      {
                          client.Credentials = new NetworkCredential("xxxx", "xxxx");
                          client.UploadFile("ftp://xxxx.xxxx.net.uk/web/wwwroot/images/", "STOR", file.FileName);
                      }
                  }
                  

                  问题:

                  出现错误找不到文件 xxxx".我知道问题是它试图找到文件,因为它是 FTP 服务器上的 "C:path-to-vs-filesexamplePhoto.jpg" ,这显然不存在.我一直在这里查看许多问题/答案,我认为我需要某种 FileStream 读/写代码.但我目前还没有完全理解这个过程.

                  Getting error "Could not find file xxxx". I understand the issue is that it's trying to find the file as it is "C:path-to-vs-filesexamplePhoto.jpg" on the FTP server, which obviously doesn't exist. I've been looking at many questions/answers on here and I think I need some kind of FileStream read/write cod. But I'm not fully understanding the process at the moment.

                  推荐答案

                  使用 IFormFile.CopyTo 或 IFormFile.OpenReadStream 来访问上传文件的内容.

                  Use IFormFile.CopyTo or IFormFile.OpenReadStream to access the contents of the uploaded file.

                  虽然 WebClient 无法使用 Stream 接口.所以你最好使用 FtpWebRequest:

                  Though WebClient cannot work with Stream interface. So you better use FtpWebRequest:

                  public void Upload(IFormFile file)
                  {
                      FtpWebRequest request =
                          (FtpWebRequest)WebRequest.Create("ftp://ftp.example.com/remote/path/file.zip");
                      request.Credentials = new NetworkCredential("username", "password");
                      request.Method = WebRequestMethods.Ftp.UploadFile;  
                  
                      using (Stream ftpStream = request.GetRequestStream())
                      {
                          file.CopyTo(ftpStream);
                      }
                  }
                  

                  这篇关于将通过 HTTP 上传到 ASP.NET 的文件上传到 C# 中的 FTP 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:获取“(553)文件名不允许"在 FTP 服务器上重命 下一篇:在 C# 中从服务器下载后 Zip 文件损坏

                  相关文章

                  最新文章

                    <bdo id='KSTep'></bdo><ul id='KSTep'></ul>

                  <legend id='KSTep'><style id='KSTep'><dir id='KSTep'><q id='KSTep'></q></dir></style></legend>
                1. <i id='KSTep'><tr id='KSTep'><dt id='KSTep'><q id='KSTep'><span id='KSTep'><b id='KSTep'><form id='KSTep'><ins id='KSTep'></ins><ul id='KSTep'></ul><sub id='KSTep'></sub></form><legend id='KSTep'></legend><bdo id='KSTep'><pre id='KSTep'><center id='KSTep'></center></pre></bdo></b><th id='KSTep'></th></span></q></dt></tr></i><div id='KSTep'><tfoot id='KSTep'></tfoot><dl id='KSTep'><fieldset id='KSTep'></fieldset></dl></div>
                2. <small id='KSTep'></small><noframes id='KSTep'>

                      <tfoot id='KSTep'></tfoot>