简体   繁体   English

使用WebClient递归上传文件

[英]Uploading files recursively with WebClient

I am writing a .NET application in C# that needs to upload some files onto a server using FTP. 我正在用C#编写一个.NET应用程序,该应用程序需要使用FTP将一些文件上传到服务器上。 I am looking at the UploadFileAsync method provided by he WebClient class: 我正在查看他的WebClient类提供的UploadFileAsync方法:

http://msdn.microsoft.com/en-us/library/ms144232(v=vs.80).aspx http://msdn.microsoft.com/zh-CN/library/ms144232(v=vs.80).aspx

What I am curious about is what happens if I tell it to upload a directory? 我很好奇的是,如果告诉我上传目录,会发生什么?

In my dreams it would recursively upload the directory and all of its contents.... Does anybody have any experience with this, or know any way I could get all the files up there without having to go through and manually create the sub directories and upload the files one by one? 在我的梦中,它将以递归方式上载目录及其所有内容。...是否有人对此有任何经验,或者知道以任何方式无需手动创建子目录就可以将所有文件保存在那里?一张一张地上传文件?

It will not work like that. 它不会那样工作。 If you pass a directory, you'll get an error. 如果传递目录,则会出现错误。 There's no shortcut of the kind you seek, unfortunately. 不幸的是,没有您想要的捷径。

Yuo可以通过Directory.GetFiles()轻松获取文件夹中任何级别的所有文件,然后一个接一个地循环浏览并上传文件。

Under UltraVNC, when I upload a directory, it creates a zip of the directory, uploads it as a file, and unzips it there. 在UltraVNC下,当我上载目录时,它会创建该目录的zip,将其上载为文件,然后在此处解压缩。 You might want to call a script that unzips the file. 您可能要调用解压缩文件的脚本。

I just searched on stackoverflow, and I think there are better solutions. 我只是搜索了stackoverflow,我认为有更好的解决方案。

https://stackoverflow.com/questions/2252000/upload-a-folder-by-ftp https://stackoverflow.com/questions/2252000/upload-a-folder-by-ftp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM