开发者

Traverse ftp subfolders to get file sizes in C#

Was wondering if you could point me at a right direction on how to achieve this...

I'm currently working on an application that will check the filespace consumed in a remote FTP server that has folders, subfolders and files.

I managed to get some information using System.NET via FtpWebRequest, FtpResponse, WebRequestMethods & System.IO in my code. However, I'm stuck in how I could manage to traverse subdirectories using the said classes.

Was wondering if you could point me at the right direction on how I could achieve this using C#? Or if there are alternatives that I could use (i.e. powershell, windows command line, etc)? I've tried looking at Chillkat ftp2, but it is not free and 开发者_如何学JAVAsome FTP client components have no documentation nor examples on how to use it.

Thank you.


You do this the same way you would download a file. Put the directory in the URL, then set the FtpWebRequest.Method property to WebRequestMethods.Ftp.ListDirectory. This will give you the list of files/subfolders, which you can then traverse manually.

Here's a blog post showing the process, as well as using ListDirectoryDetails to differentiate between files and subdirectories.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜