Enhanced FTP Code

Here is the enhanced version of the code which sends files to remote computer using FTP which I have posted long back!

Public Function CheckDir(ByVal FolderName As String, ByVal thePath As String) As Boolean
Dim sr As StreamReader = Nothing
Dim dirList() As String = Nothing
Dim myFtpReq As FtpWebRequest = FtpWebRequest.Create(New Uri(thePath))
myFtpReq.Method = WebRequestMethods.Ftp.ListDirectory
myFtpReq.KeepAlive = False
myFtpReq.Proxy = Nothing
myFtpReq.UsePassive = True
myFtpReq.Credentials = New NetworkCredential(userName, paswd)
Dim myFtpResp As FtpWebResponse = CType(myFtpReq.GetResponse(), FtpWebResponse)
Dim ftpRespStream As Stream = myFtpResp.GetResponseStream()
sr = New StreamReader(ftpRespStream, System.Text.Encoding.Default)
Dim folderList As String = sr.ReadToEnd()
‘MsgBox(“Folder List: ” & folderList)
If Not folderList Is Nothing Or folderList <> “” Then
For Each theDir In folderList.Split(vbCrLf)
If theDir.Contains(“/”) Then
If FolderName = theDir.Split(“/”)(1) Then
‘MsgBox(FolderName & ” Folder exist “)
Return True
End If
End If
End If
Return False
Catch ex As Exception
MessageBox.Show(“Error: ” & ex.Message & ” | ” & ex.StackTrace)
Return 0
If Not sr Is Nothing Then
sr = Nothing
End If
End Try
End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s