connection to FTP server

I am trying to connect to a FTP server using the FtpWebRequest class in
visual basic 2005. Right now, I am merely trying to get a list of files
on the server. I have the IP address, the username and password to the
server. I also had to install a certificate in my browser. I get a "The
specified network password is not correct" - error when trying to test
the code. I get it after the Client certificates statement.

Public Shared Function ListFilesOnServerSsl(ByVal serverUri As Uri) As
String

Dim username As String = "username"
Dim password As String = "password"
Dim retStr As String = ""

' The serverUri should start with the ftp:// scheme.
If Not (serverUri.Scheme = Uri.UriSchemeFtp) Then
retStr = ""
Else
'Get the object used to communicate with the server.
Dim request As FtpWebRequest =
CType(WebRequest.Create(serverUri), FtpWebRequest)
request.Credentials = New NetworkCredential(username,
password)

request.ClientCertificates.Add(X509Certificates.X509Certificate.CreateFromC-ertFile("C:\certificate.pfx"))
request.Method = WebRequestMethods.Ftp.ListDirectory
request.EnableSsl = True

'Get the ServicePoint object used for this request
Dim sp As ServicePoint = request.ServicePoint
sp.ConnectionLimit = 2
Dim Response As FtpWebResponse = CType(request.GetResponse,
FtpWebResponse)

'The following streams are used to read the data returned
from the server.
Dim responseStream As Stream = Nothing
Dim readStream As StreamReader = Nothing
Try
responseStream = Response.GetResponseStream
readStream = New StreamReader(responseStream,
System.Text.Encoding.UTF8)
If Not (readStream Is Nothing) Then
retStr = readStream.ReadToEnd()
End If
Finally
If Not (readStream Is Nothing) Then
readStream.Close()
End If
If Not (Response Is Nothing) Then
Response.Close()
End If
End Try
End If

Return retStr
End Function
End Class

I made sure the username and password are correct. Can someone point
out where I am going wrong



Answer this question

connection to FTP server