We are using visual studio 2005, The latest version of Xceed, .net 2.0 and vista ultimate on a x64 system.
I have tried this on both a 32 bit and a 64 bit system.
================================================================
The error provided is:
================================================================
Xceed.Ftp.FtpSslException: An SSL error occurred while sending a command. ---> Xceed.Utils.Security.SecurityException: An error occured while communicating with the remote host. ---> Xceed.Utils.Security.Ssl.Shared.SslException: The certificate could not be verified.
at Xceed.Utils.Security.Ssl.Shared.HandshakeLayer.VerifyChain(CertificateChain chain, Boolean client)
at Xceed.Utils.Security.Ssl.Shared.HandshakeLayer.ProcessCertificate(HandshakeMessage message, Boolean client)
at Xceed.Utils.Security.Ssl.Shared.ClientHandshakeLayer.ProcessMessage(HandshakeMessage message)
at Xceed.Utils.Security.Ssl.Shared.HandshakeLayer.ProcessMessages(RecordMessage message)
at Xceed.Utils.Security.Ssl.Shared.RecordLayer.ProcessBytes(Byte[] buffer, Int32 offset, Int32 size)
at Xceed.Utils.Security.Ssl.Shared.CompatibilityLayer.ProcessServerHello(Byte[] bytes, Int32 offset, Int32 size)
at Xceed.Utils.Security.Ssl.Shared.CompatibilityLayer.ProcessHello(Byte[] bytes, Int32 offset, Int32 size)
at Xceed.Utils.Security.Ssl.Shared.SocketController.OnReceive(IAsyncResult ar)
--- End of inner exception stack trace ---
at Xceed.Utils.Security.Ssl.SecureSocket.EndSend(IAsyncResult asyncResult)
at Xceed.Utils.Security.Ssl.SecureSocket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at Xceed.Ftp.Engine.FtpCommandChannel.SendString(String command)
--- End of inner exception stack trace ---
at Xceed.Ftp.Engine.FtpCommandSequence.EndExecute(IAsyncResult asyncResult)
at Xceed.Ftp.FtpClient.Authenticate(FtpCommandChannel commandChannel, AuthenticationFtpCommand authCommand, DataChannelProtectionFtpCommand protCommand)
at Xceed.Ftp.FtpClient.Authenticate(AuthenticationMethod authenticationMethod, VerificationFlags verificationFlags, Certificate clientCertificate, DataChannelProtection dataProtection)
at ConsoleApplication2.Module1.Example() in c:\work\PeopleSoft\ConsoleApplication2\ConsoleApplication2\Module1.vb:line 107
================================================================
the code to call is:
================================================================
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports Xceed.Ftp
Imports Xceed.FileSystem
Module Module1
Sub Main()
Example()
End Sub
Public Sub Example()
' We will connect to the following FTP server, using the specified
' username and password.
Dim hostname As String = xxxxxxxxxx
Dim username As String = xxxxxxxxxx
Dim password As String = xxxxxxxxxx
Dim connection As FtpConnection = Nothing
Try
' Connecting securely and authenticating are two distinct
' methods of establishing a secure connection with an FTP
' server. In the first case, the Secure FTP server may require
' an SSL connection to be established the very first thing. We
' call this an IMPLICIT SSL connection. In the second case,
' the connection is established in clear text and a special
' FTP command must be sent to the Secure FTP server to change
' the connection into an SSL/TLS connection. We call this an
' EXPLICIT SSL connection.
Dim client As New FtpClient()
Dim clientCert As Certificate = Nothing
' Most FTP servers that support explicit TLS authentication accept a
' normal connection on port 21.
'connection = New FtpConnection( _
' hostname, _
' 21, _
' username, _
' password, _
' AuthenticationMethod.Tls, _
' VerificationFlags.None, _
' Nothing, _
' DataChannelProtection.Private, _
' False)
client.Connect(hostname)
' You must then authenticate before logging-in, using the
' Authenticate method. When securing the connection explicitly,
' you can indicate if you wish to secure data connections as
' well, using the overload which takes a DataChannelProtection
' parameter. The default value is "Clear".
client.Authenticate( _
AuthenticationMethod.Tls, VerificationFlags.None, clientCert, _
DataChannelProtection.Private)
client.Login(username, password)
Console.WriteLine("Logged-in!")
' In order to consult the server certificate, we must advise
' for the CertificateReceived event.
AddHandler connection.CertificateReceived, AddressOf OnCertificateReceived
' And to allow WinForms actions within the above event, we'll need
' to redirect the call to the main thread. To achieve this, we must
' set the SynchronizingObject property of the FtpConnection.
' Keep in mind that the library will then pump messages by calling Application.DoEvents().
' connection.SynchronizingObject = m_resultsForm
' Let's trace commands and replies to the console.
connection.TraceWriter = Console.Out
' Now that the connection object is instanciated, we can proceed with a simple listing
' of the current directory.
Dim folder As FtpFolder = New FtpFolder(connection)
Dim items As FileSystemItem() = folder.GetItems(False)
For Each item As FileSystemItem In items
Console.WriteLine(vbCrLf & item.HostedFullName)
Next item
Catch except As Exception ' FileSystemException
Console.WriteLine(vbCrLf & except.ToString())
Dim bob As String = Console.Read()
Finally
If Not connection Is Nothing Then
connection.Dispose()
' Unsubscribe from events.
RemoveHandler connection.CertificateReceived, AddressOf OnCertificateReceived
End If
End Try
End Sub
Private Sub OnCertificateReceived(ByVal sender As Object, ByVal e As CertificateReceivedEventArgs)
' The Status argument property tells you if the server certificate was accepted
' based on the VerificationFlags you provided.
If e.Status <> VerificationStatus.ValidCertificate Then
Console.WriteLine(vbCrLf & "The server certificate is invalid: {0}", e.Status.ToString())
Console.WriteLine(vbCrLf & e.ServerCertificate.ToString())
' You have three choices here.
' 1) Refuse the certificate by setting e.Action to VerificationAction.Reject,
' thus making the authentication fail. This is e.Action's default value
' when the server certificate isn't valid
' 2) Set e.Flags to less restrictive criterias and ask the library to
' validate the certificate again by setting e.Action to
' VerificationAction.VerifyAgain.
' 3) Force the library to accept this certificate by setting e.Action to
' VerificationAction.Accept.
' We'll do #1 or #3, depending on the user's answer.
Console.WriteLine(vbCrLf & "Do you want to accept this certificate anyway? [Y/N]")
Dim answer As Integer = Console.Read()
If Microsoft.VisualBasic.ChrW(answer) = "y"c _
Or Microsoft.VisualBasic.ChrW(answer) = "Y"c Then
e.Action = VerificationAction.Accept
End If
Else
' e.Action's default value is VerificationAction.Accept
Console.WriteLine(vbCrLf & "Valid certificate received from server.")
End If
End Sub
End Module