0

I need help, none i can't seem to find a solution to my problem.

I'm trying to create a directory in FTP Server:

Dim request As FtpWebRequest = FtpWebRequest.Create("ftp:\\*******")
        Dim creds As NetworkCredential = New NetworkCredential("****", "*****")
        request.Credentials = creds
        request.KeepAlive = True
        request.EnableSsl = True
        request.UsePassive = True

        request.Timeout = 10000000
        request.ReadWriteTimeout = 10000000
        ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf customCertValidation)

        Dim resp As FtpWebResponse = Nothing
        request.Method = WebRequestMethods.Ftp.ListDirectoryDetails

        Using resp
            resp = request.GetResponse()
            Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.ASCII)
            Dim s As String = sr.ReadToEnd()
            If Not s.Contains("newfolder") Then

                request = FtpWebRequest.Create("ftp:\\********")
                request.Credentials = creds
                request.Method = WebRequestMethods.Ftp.MakeDirectory
                resp = request.GetResponse()
                Console.WriteLine(resp.StatusCode & "Created")
            Else
                Console.WriteLine("Directory already exists")
            End If
        End Using
    Catch ex As Exception
        Console.WriteLine(ex.ToString)
    End Try

Function for customCertValidation

Function customCertValidation(ByVal sender As Object,
                                            ByVal cert As X509Certificate,
                                            ByVal chain As X509Chain,
                                            ByVal errors As SslPolicyErrors) As Boolean
    Return True
End Function

I get the following error:

enter image description here

I have tried everything on the web but nothing seems to work, can someone please tell me what is wrong. Thank You

a ridi
  • 125
  • 2
  • 13
  • You have two calls to `FtpWebRequest.GetResponse` - which is throwing the exception? One possibility - isn't port 22 SSH, not FTP? The slashes should also be forward - `ftp://...`, but that seems unlikely to be the issue. – Mark Jul 28 '17 at 15:49
  • Port 22 is SFTP, however using ftp open allows the connection so we believe the ftp server is allowing both. – a ridi Jul 28 '17 at 16:55
  • The message "The server committed a protocol violation" may indicate that it doesn't actually support both. Perhaps try something like [SSH.NET](https://github.com/sshnet/SSH.NET) and see if that works? – Mark Jul 28 '17 at 17:33

0 Answers0