Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SFTP using FtpWebRequest class?

SFTP using FtpWebRequest class?

Scheduled Pinned Locked Moved C#
csharpcomsysadminsecuritycryptography
8 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Weibel
    wrote on last edited by
    #1

    I am attempting to read an SFTP directory using the FtpWebRequest class, but am getting the error 'Unable to connect to the remote server'. Here is my code: Private Sub List(ByVal listUrl As String, ByVal username As String, ByVal password As String)  Dim reader As StreamReader = Nothing  Dim listRequest As FtpWebRequest = WebRequest.Create(New System.Uri(listUrl))  System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy  listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails  listRequest.KeepAlive = True  listRequest.EnableSsl = True  listRequest.Credentials = New NetworkCredential(username, password)  Dim listResponse As FtpWebResponse = listRequest.GetResponse()  reader = New StreamReader(listResponse.GetResponseStream()) End Sub Public Class TrustAllCertificatePolicy  Implements System.Net.ICertificatePolicy   Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, _ ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, _ ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult  Return True  End Function End Class I appreciate any advice you can provide into what I'm missing. Thank you,

    Jason W.

    L 2 Replies Last reply
    0
    • J Jason Weibel

      I am attempting to read an SFTP directory using the FtpWebRequest class, but am getting the error 'Unable to connect to the remote server'. Here is my code: Private Sub List(ByVal listUrl As String, ByVal username As String, ByVal password As String)  Dim reader As StreamReader = Nothing  Dim listRequest As FtpWebRequest = WebRequest.Create(New System.Uri(listUrl))  System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy  listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails  listRequest.KeepAlive = True  listRequest.EnableSsl = True  listRequest.Credentials = New NetworkCredential(username, password)  Dim listResponse As FtpWebResponse = listRequest.GetResponse()  reader = New StreamReader(listResponse.GetResponseStream()) End Sub Public Class TrustAllCertificatePolicy  Implements System.Net.ICertificatePolicy   Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, _ ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, _ ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult  Return True  End Function End Class I appreciate any advice you can provide into what I'm missing. Thank you,

      Jason W.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Jason, you posted a VB.NET question in the C# forum. :)

      led mike

      J 1 Reply Last reply
      0
      • L led mike

        Jason, you posted a VB.NET question in the C# forum. :)

        led mike

        J Offline
        J Offline
        Jason Weibel
        wrote on last edited by
        #3

        Vb.net and c# are the same thing, more people visit this forum so I figure there is a better chance of getting an answer here.

        Jason W.

        L 1 Reply Last reply
        0
        • J Jason Weibel

          Vb.net and c# are the same thing, more people visit this forum so I figure there is a better chance of getting an answer here.

          Jason W.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Jason Weibel wrote:

          Vb.net and c# are the same thing

          :wtf:

          led mike

          J 1 Reply Last reply
          0
          • L led mike

            Jason Weibel wrote:

            Vb.net and c# are the same thing

            :wtf:

            led mike

            J Offline
            J Offline
            Jason Weibel
            wrote on last edited by
            #5

            Here is the C# version - I'm really not interested in getting into a C# is better then vb debate. I just want get this working so I can move on to the next item on my to do list. private void List(string listUrl, string username, string password) { StreamReader reader = null; FtpWebRequest listRequest = WebRequest.Create(new System.Uri(listUrl)); System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; listRequest.KeepAlive = true; listRequest.EnableSsl = true; listRequest.Credentials = new NetworkCredential(username, password); FtpWebResponse listResponse = listRequest.GetResponse(); reader = new StreamReader(listResponse.GetResponseStream()); } public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy { public bool CheckValidationResult(System.Net.ServicePoint srvPoint, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Net.WebRequest request, int certificateProblem) { return true; } }

            Jason W.

            1 Reply Last reply
            0
            • J Jason Weibel

              I am attempting to read an SFTP directory using the FtpWebRequest class, but am getting the error 'Unable to connect to the remote server'. Here is my code: Private Sub List(ByVal listUrl As String, ByVal username As String, ByVal password As String)  Dim reader As StreamReader = Nothing  Dim listRequest As FtpWebRequest = WebRequest.Create(New System.Uri(listUrl))  System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy  listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails  listRequest.KeepAlive = True  listRequest.EnableSsl = True  listRequest.Credentials = New NetworkCredential(username, password)  Dim listResponse As FtpWebResponse = listRequest.GetResponse()  reader = New StreamReader(listResponse.GetResponseStream()) End Sub Public Class TrustAllCertificatePolicy  Implements System.Net.ICertificatePolicy   Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, _ ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, _ ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult  Return True  End Function End Class I appreciate any advice you can provide into what I'm missing. Thank you,

              Jason W.

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              Jason Weibel wrote:

              I am attempting to read an SFTP directory using the FtpWebRequest class

              Are you sure the Server is running?

              led mike

              J 1 Reply Last reply
              0
              • L led mike

                Jason Weibel wrote:

                I am attempting to read an SFTP directory using the FtpWebRequest class

                Are you sure the Server is running?

                led mike

                J Offline
                J Offline
                Jason Weibel
                wrote on last edited by
                #7

                The server is running and I have no problem connecting with WS-FTP. I'm starting to wonder if FtpWebRequest works for SFTP. I have been reading some blogs and others are having the same problem but no one has a solution. Here are some links: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=346870&SiteID=1 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=532122&SiteID=1 At this point I'm going to look into other ways to get this resolved.

                Jason W.

                L 1 Reply Last reply
                0
                • J Jason Weibel

                  The server is running and I have no problem connecting with WS-FTP. I'm starting to wonder if FtpWebRequest works for SFTP. I have been reading some blogs and others are having the same problem but no one has a solution. Here are some links: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=346870&SiteID=1 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=532122&SiteID=1 At this point I'm going to look into other ways to get this resolved.

                  Jason W.

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  Yes this entry from that blog holds the key

                  Actually, .NET 2.0 does not currently support implicit SSL, only explicit.  We will consider adding this for a future release.

                  led mike

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups