VB.NET读取FTP服务器中的所有文件夹 [英] VB.NET read all folders in FTP Server

查看:602
本文介绍了VB.NET读取FTP服务器中的所有文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,用于显示FTP服务器中某个文件夹内的所有文件,
但我不知道如何查看FTP服务器或
内的文件夹 在另一个文件夹中.

这是显示文件夹内文件的代码

I have a code for displaying all files inside a folder in a FTP Server,
but I dont know how to view a folder inside of a FTP Server or
inside an another folder.

Here''s the code to display a file inside a folder

reqFTP = DirectCast(WebRequest.Create("ftp://ftp.microsoft.com/"), FtpWebRequest)
        reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails
        reqFTP.Credentials = New NetworkCredential(UserID, Password)
        response = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
        Dim responseStream As Stream = response.GetResponseStream()
        Dim reader As New StreamReader(responseStream)
        Dim CrLf As Char() = {Constants.vbCr, Constants.vbLf}
        Dim lines() As String = reader.ReadToEnd().Split(CrLf, StringSplitOptions.RemoveEmptyEntries)
        Dim lineArr() As String
        For i As Integer = 0 To UBound(lines)
            lineArr = Split(lines(i))
            lstFTPfiles.Items.Add(lineArr(UBound(lineArr)))
        Next
        responseStream.Close()
        response.Close()
        reader.Close()



ftp://ftp.microsoft.com/
中的示例 在根目录中,它有一个子文件夹



Example in ftp://ftp.microsoft.com/
In root directory it has a sub folders

Folder1
Folder2



我想将这两个子文件夹放在ListBox中.



I want to put that two sub folders in a ListBox.

推荐答案

我用Google搜索了"vb.net ftp递归目录列表",并发现了以下内容:

http://blogs.msdn.com/b/robert_mcmurray/archive/2009/09/05/creating-recursive-directory-listing-files-for-ftp-clients.aspx [
I googled "vb.net ftp recursive directory listing", and found this:

http://blogs.msdn.com/b/robert_mcmurray/archive/2009/09/05/creating-recursive-directory-listing-files-for-ftp-clients.aspx[^]


这篇关于VB.NET读取FTP服务器中的所有文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆