VB.NET从FTP服务器读取文件夹中的所有文件
我正在尝试从FTP服务器获取文件夹中的所有文件
我在Internet上找到了执行此操作的代码
I''m trying to get all the files inside a folder from a FTP Server
I found a code for doing this in Internet
Dim reqFTP As FtpWebRequest = Nothing
reqFTP = DirectCast(WebRequest.Create("ftp://ftp.microsoft.com/Products/mediaplayer/MACOS/"), 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)
Console.WriteLine(reader.ReadToEnd())
Console.WriteLine中的结果为
Result in Console.WriteLine is
09-28-98 04:51PM 3149614 MacOSPlayer3.1b1c7.hqx
09-17-98 09:43AM 6035 MacReadMe.txt
我的问题是当我使用 reader.ReadToEnd()
并将其放在ListBox中,结果只是一行.
my problem is when I''m using the reader.ReadToEnd()
and put it in a ListBox, the result is just one line.
09-28-98 04:51PM 3149614 MacOSPlayer3.1b1c7.hqx**09-17-98 09:43AM 6035 MacReadMe.txt**
*是一个我不知道它是什么的字符,它有点像一个矩形字符
如何将结果放入列表框,但结果与控制台相同.
任何建议表示赞赏
谢谢....
* is a character i don''t know what it is, its kinda a rectangle type character
How can I put the result in a ListBox but the result is the same with the Console.
Any suggestion is appreciated
Thanks....
reader.ReadToEnd返回一个字符串.因此,这是显示为一行的一项结果.使用string.split拆分行.
reader.ReadToEnd returns a string. So this is one result displayed as one line. Use string.split to split the lines.
Dim Lf As Char = ToChar(CByte(10))
Dim Cr As Char = ToChar(CByte(13))
Dim CrLf As Char() = {Cr, Lf}
Dim lines() as string = reader.ReadToEnd().Split(CrLf, StringSplitOptions.RemoveEmptyEntries)
**是回车符(CrLf).
The ** are the cariage return linefeed (CrLf) characters.