views:

91

answers:

1

Has anyone successfully used the .Net FTPWebRequest class to ftps to a remote server from behind a NAT? My code is as follows:

 Dim URI = "ftp://" & sRemoteDir & "/"
    Dim ftp As FtpWebRequest = Nothing
  Try
   ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateServerCertificate
   ftp = CType(FtpWebRequest.Create(URI), FtpWebRequest)
   ftp.CachePolicy = New System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore)
   ftp.Credentials = New NetworkCredential(sUID, sPw)
   ftp.EnableSsl = True
   ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails

   Dim response As FtpWebResponse = CType(ftp.GetResponse(), FtpWebResponse)
   Dim responseStream As Stream = response.GetResponseStream
   Dim streamReader As New StreamReader(responseStream)
   Dim sb As New StringBuilder()
   sb.Append(streamReader.ReadToEnd)
   streamReader.Close()
   response.Close()
   Return sb.ToString()
  Catch ex As Exception
   Return (ex.Message)
  End Try

And I get the following exception:

"Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."

I know the code is good, as it works if the machine is not behind a NAT. Any ideas? The machine has a static IP and all ports are open for traffic to/from the specified host.