Public Function GetFileList(ByVal rootpath As String, ByVal Directory As String) As ArrayList
Dim ftpserverip As String
Dim ftpuserid As String = "userid"
Dim ftppassword As String = "password"
Dim strList As New ArrayList
Dim sr As StreamReader = Nothing
Dim fwr As FtpWebRequest
rootpath.Replace("ftp://", "")
If Not rootpath.EndsWith("/") Then
rootpath += "/"
End If
ftpserverip = rootpath & Directory
Try
fwr = DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ftpserverip)), FtpWebRequest)
fwr.Credentials = New NetworkCredential(ftpuserid, ftppassword)
fwr.Method = WebRequestMethods.Ftp.ListDirectoryDetails
fwr.UsePassive = False
sr = New StreamReader(fwr.GetResponse().GetResponseStream())
Catch ex As WebException
Dim status As String = DirectCast(ex.Response, FtpWebResponse).StatusDescription
MsgBox(status, MsgBoxStyle.Information, "It didn't work")
End Try
If Not sr Is Nothing Then
Dim str As String = sr.ReadLine()
Do While Not sr.EndOfStream
If Not str.ToUpper.Contains("") Then
str = str.Substring(str.IndexOf(" ")).Trim
str = str.Substring(str.IndexOf(" ")).Trim
str = str.Substring(str.IndexOf(" ")).Trim
strList.Add(str)
End If
str = sr.ReadLine()
Loop
sr.Close()
sr = Nothing
fwr = Nothing
End If
Return strList
End Function
|