S
Schoo
I have a directory on a server called "content" and my goal is to return a
list of files/dirs (I need to differentiate between the two in the returned
data) from that directory in code. I determined that I can't use a static
directory to do this (the DIR commad) so FTP seems to be the option I want.
I set up IIS on the content server to 'open up' the content folder with no
security (for now) and I can open up IE6 on a workstation and access the
file structure by typeing ftp://<IP Address> into the address line. So, I
know the security allows IE to get in.
Next, I read KB#812404 and created a test project, importing ftp.vb and
ftpwebrequest.vb into the project as a class library. I have stepped
through the process in debug and I am able to follow it as it moves into the
classes so I know I am referencing the classes properly in code. Also, the
Output window is filling with data (much of it I don't understand), so it
appears to be working with the parameters. The problem is that I am not
able to get a list of the files in the directory.
Can anyone tell me what I might be doing wrong? Has anyone had this problem
with FTP connections in .NET before? Any suggestions or pointers to better
VB.NET examples would be appreciated.
Scott
PS. To recreate what I am doing, import the classes from the KB article
into a library, reference it in your main web project and add the following
(simplified) code to a form:
=================================================================
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim creator As FtpRequestCreator = New FtpRequestCreator
WebRequest.RegisterPrefix("ftp:", creator)
End Sub
Private Sub cmdFTP_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdFTP.Click
txtContents.Text = fetch(txtFTP.Text)
End Sub
Private Function fetch(ByVal uri As String) As String
Dim req As WebRequest
Dim resp As WebResponse
req = WebRequest.Create(uri)
resp = req.GetResponse
Dim strTest(1) As String
strTest(0) = "-u" & uri
strTest(1) = "-mdir"
Main(strTest)
Dim reader As IO.StreamReader
reader = New IO.StreamReader(resp.GetResponseStream())
Dim retval As String
retval = reader.ReadToEnd()
reader.Close()
End Function
=================================================================
list of files/dirs (I need to differentiate between the two in the returned
data) from that directory in code. I determined that I can't use a static
directory to do this (the DIR commad) so FTP seems to be the option I want.
I set up IIS on the content server to 'open up' the content folder with no
security (for now) and I can open up IE6 on a workstation and access the
file structure by typeing ftp://<IP Address> into the address line. So, I
know the security allows IE to get in.
Next, I read KB#812404 and created a test project, importing ftp.vb and
ftpwebrequest.vb into the project as a class library. I have stepped
through the process in debug and I am able to follow it as it moves into the
classes so I know I am referencing the classes properly in code. Also, the
Output window is filling with data (much of it I don't understand), so it
appears to be working with the parameters. The problem is that I am not
able to get a list of the files in the directory.
Can anyone tell me what I might be doing wrong? Has anyone had this problem
with FTP connections in .NET before? Any suggestions or pointers to better
VB.NET examples would be appreciated.
Scott
PS. To recreate what I am doing, import the classes from the KB article
into a library, reference it in your main web project and add the following
(simplified) code to a form:
=================================================================
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim creator As FtpRequestCreator = New FtpRequestCreator
WebRequest.RegisterPrefix("ftp:", creator)
End Sub
Private Sub cmdFTP_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdFTP.Click
txtContents.Text = fetch(txtFTP.Text)
End Sub
Private Function fetch(ByVal uri As String) As String
Dim req As WebRequest
Dim resp As WebResponse
req = WebRequest.Create(uri)
resp = req.GetResponse
Dim strTest(1) As String
strTest(0) = "-u" & uri
strTest(1) = "-mdir"
Main(strTest)
Dim reader As IO.StreamReader
reader = New IO.StreamReader(resp.GetResponseStream())
Dim retval As String
retval = reader.ReadToEnd()
reader.Close()
End Function
=================================================================