C# - FtpWebRequest 的多种方法?

标签 c# ftpwebrequest

我正在开发一个程序,将多个文件上传到 FTP。为此,我需要完成 8 个操作:

  • 在 FTP 中创建一个新文件夹
  • 将三个文件上传到新目录
  • 在新目录中创建三个子目录

根据我收集的信息,我只能处理 FtpWebRequest 中的一种方法,如下所示:

FtpWebrequest request = WebRequest.Create("ftp://microsoft.com/NewDir/") as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new NetworkCredentials("username", "password");
FtpWebResponse response = request.GetResponse() as FtpWebResponse;

response.Close();

那么我是否必须编写代码来创建子目录并单独流式传输文件上传?或者是否可以在单个连接内完成所有这些?

这是我的第一篇文章,如果格式困惑,我深表歉意。

最佳答案

From what I've gathered, I'm only able to process one method in FtpWebRequest, much like this: ...

您不必关闭连接。只需处理您的请求,从服务器获取响应,就像您的 [request.GetResponse()] 一样,然后继续下一个方法。完成所有操作后,关闭连接。

您可以设置的方法列表位于枚举 WebRequestMethods.Ftp 中。请访问this查看它们链接。

关于C# - FtpWebRequest 的多种方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8235085/

相关文章:

.net - FTPWebRequest上传文件只会上传两个文件!

.net - 启用 "Require TLS session resumption on data connection when using PROT P"的 FileZilla 服务器上基于 SSL/TLS 的 FtpWebRequest

c# - 有序执行线程

c# - 在 Web 应用程序中在哪里以及如何使用拦截器?

javascript - 为什么 Ajax 调用没有被命中?

c# - Excel VSTO 异步按钮 - 用户交互的奇怪行为?

c# - 使用 SQLConnection 连接到 SQL CE 数据库

.net - 如何重用 FtpWebRequest 连接

c# - 解析 FtpWebRequest ListDirectoryDe​​tails 行

c# - FtpWeb 请求错误 : 550 Size not allowed in ASCII mode