VB.Net Get FTP list of files
09-May-1313 Leave a comment
Code:
Imports System.Net Public Class FTP1 Private host As String Private username As String Private password As String Sub New(hostValue As String, usernameValue As String, passwordValue As String) host = hostValue username = usernameValue password = passwordValue End Sub Function GetFileList() As List(Of String) Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(host), System.Net.FtpWebRequest) ftp.Credentials = New System.Net.NetworkCredential(username, password) ftp.KeepAlive = False ftp.UseBinary = True ftp.Method = WebRequestMethods.Ftp.ListDirectory Dim streamReader As New IO.StreamReader(ftp.GetResponse.GetResponseStream) Dim result As New List(Of String) Dim line = streamReader.ReadLine While Not String.IsNullOrEmpty(line) result.Add(line) line = streamReader.ReadLine End While Return result End Function End Class