Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

? FTP in Framework 2.0 ?

Status
Not open for further replies.

nomaam22

Programmer
Oct 6, 2006
9
CA
I am working with Visual Studio 2005; framework 2.0, in a VB windows form.

I am trying to establish a connection with a FTP server and obtain a list of its contents. So far i am working with an example provided by microsoft.

The problem i am having is that i do not know how to use the GetFiles and GetDirectories functions so i can find out what is a file and what is a directory.

Below is a copy of the code that i am using. If someone could show me how to simply use the GetFiles and GetDirectories functions it would be much appreciated.

Thanks.

Code:

===============================================

Imports System.net
Imports System.IO

Public Class Form1

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

Dim host As String = "ftp://spider.macomnet.ru/pub"
Dim username As String = "Anonymous@Anonymous.com"
Dim password As String = ""

Dim reader As StreamReader = Nothing
Try
Dim listRequest As FtpWebRequest = WebRequest.Create(host)
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails

Dim listResponse As FtpWebResponse = listRequest.GetResponse()
reader = New StreamReader(listResponse.GetResponseStream())
txtOutput.Text = (reader.ReadToEnd())
txtOutput.Text &= "List complete."

Catch ex As UriFormatException
txtOutput.Text &= ex.Message
Catch ex As WebException
txtOutput.Text &= ex.Message
Finally
If reader IsNot Nothing Then
reader.Close()
End If
End Try
End Sub


End Class

================================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top