如何列出FTP连接的目录内容 [英] How to list directory contents of an FTP connection

查看:139
本文介绍了如何列出FTP连接的目录内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到这个教程。在VB.NET中,我想做一个如下命令:

  Dim array1()as string = ListFilesInFolder(www.example / b 



我知道这可能不会那么简单,但任何人都可以指向我的教程或任何东西?

解决方案

使用此免费库 http://netftp.codeplex.com/

 进口System.Net 
Imports System.Net.FtpClient

Sub Main
使用ftp = new FtpClient()

ftp.Host =www.example.com
ftp.Credentials = new NetworkCredential(yourFTPUser,yourFTPPassword)
ftp.SetWorkingDirectory(/ images)
用于ftp.GetListing(ftp.GetWorkingDirectory())中的每个项目

select case item.Type
case FtpFileSystemObjectType.Directory:
Console.WriteLine(Folder:+ item.FullName)
case FtpFileSystemObjectType.File:
Console.WriteLine(File:+ item.FullName)
End Select
Next
End使用
End Sub

当然,我假设www.example.com是一个FTP服务器。



重要提示:库需要完整的 Framework 4.0 。你应该到你的项目属性的生成页面,点击高级选项并选择 Framework 4.0 而不是 Framework 4.0 Client Profile


I can't find a tutorial on this. In VB.NET I want to do a command such as:

Dim array1() as string = ListFilesInFolder("www.example.com/images")

I know this is probably not going to be that simple, but can anyone point me to a tutorial or anything?

解决方案

use this free library http://netftp.codeplex.com/

Imports System.Net
Imports System.Net.FtpClient

Sub Main
    using ftp = new FtpClient()

        ftp.Host = "www.example.com"
        ftp.Credentials = new NetworkCredential("yourFTPUser", "yourFTPPassword")
        ftp.SetWorkingDirectory("/images")
        for each item in ftp.GetListing(ftp.GetWorkingDirectory())

            select case item.Type
                case FtpFileSystemObjectType.Directory:
                    Console.WriteLine("Folder:" + item.FullName)
                case FtpFileSystemObjectType.File:
                    Console.WriteLine("File:" + item.FullName)
            End Select
        Next
    End Using    
End Sub

of course I'm assuming that www.example.com is a FTP server.

AN IMPORTANT NOTE: The library requires the complete Framework 4.0. You should go to the Build Page of your Project Properties, click on the Advanced Options and select Framework 4.0 instead of Framework 4.0 Client Profile

这篇关于如何列出FTP连接的目录内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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