Home Forums .NET libraries Xceed SFTP/FTP for .NET Error uploading files using Implicit FTPS

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21120 |

    I’ve written a VB.Net utility to upload files to a server using either FTP or implicit secure FTP. The unsecured FTP works but the implicit secure FTP does not. The process logs in properly to the FTP server, creates the folders needed but fails to upload the files. Each file times out with the following… “An error occurred while opening a file for writing.” The exception type is Xceed.Ftp.FtpFile and the FullName points to the filename on the FTP server. We know the FTP server is set up properly because we can upload the files manually using a different implicit secure FTP client.

    I’ve downloaded the latest version of the Ultimate Suite, version 3.2.8557.11540 and we are using version 3.7 of Xceed.FTP.dll

    Is there something I’m doing wrong?

    Below is the code used…

        Private Sub FTP_Files(ByVal strFolder As String, ByVal strOption As String)
            Dim sb As New StringBuilder
            Dim boolError As Boolean
            Dim i As Integer
            Dim aDirs() As String
            Dim aFiles() As String

            ‘The Xceed package used is the Ultimate Suite – 2008 Version
            Xceed.FileSystem.Licenser.LicenseKey = “FTN37-xxxxx-xxxxx-xxxA”
            Xceed.Ftp.Licenser.LicenseKey = “FTN37-xxxxx-xxxxx-xxxA”

            Dim connection As FtpConnection = Nothing
            Dim events As New FileSystemEvents()

            ‘ Another way to get a log of commands, replies, connections and
            ‘ disconnections is to assign a TextWriter to the TraceWriter property.
            intLog += 1
            sb.Remove(0, sb.Length)
            sb.Append(System.IO.Path.GetTempPath())
            sb.Append(“guidstftp”)
            sb.Append(intLog.ToString)
            sb.Append(“.log”)
            Dim logFilename As String = sb.ToString

            sb.Remove(0, sb.Length)
            sb.Append(“Staging “)
            sb.Append(strFolder)
            sb.Append(” to “)
            sb.Append(objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“DSTLOC”).ToString)
            dgvProgress.Rows.Add(sb.ToString, “In Process”, “guidstftp” + intLog.ToString)

            Try

                If strOption = “F” Then
                    ‘Unsecured FTP
                    connection = New FtpConnection( _
                      objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“FTPSVR”).ToString, _
                      objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“FTPUSR”).ToString, _
                      DecryptString(objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“FTPPWD”).ToString))
                Else
                    ‘ 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.
                    ‘*************************************************************
                    ‘ Here we will use the IMPLICIT SSL connection…
                    ‘*************************************************************
                    ‘ When using implicit SSL/TLS connections, it means the FTP server requires
                    ‘ the SSL authentication to occur right away, before it sends
                    ‘ its initial welcome message. The AuthenticationMethod.Tls
                    ‘ value implies both SSL 3.1 and SSL 3.0 are supported. Most
                    ‘ FTP servers that require an implicit SSL connection listen
                    ‘ on port 990 rather than 21.
                    connection = New FtpConnection( _
                      objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“FTPSVR”).ToString, _
                      990, _
                      objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“FTPUSR”).ToString, _
                      DecryptString(objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“FTPPWD”).ToString), _
                      AuthenticationMethod.Tls, _
                      VerificationFlags.AllowTestRoot, _
                      Nothing, _
                      DataChannelProtection.Private, _
                      True)

                    ‘ In order to consult the server certificate, we must advise
                    ‘ for the CertificateReceived event.
                    AddHandler connection.CertificateReceived, AddressOf OnCertificateReceived
                End If

                ‘ Set up an IO StreamWriter for FTP logging.
                connection.TraceWriter = New System.IO.StreamWriter(logFilename)

                ‘ In order to display file copy progression add the event handler…
                AddHandler events.ByteProgression, AddressOf OnByteProgression

                ‘ In order to offer “skip and continue” support when manipulating
                ‘ many files, you can handle the ItemException event.
                AddHandler events.ItemException, AddressOf OnItemException

                ‘ 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 = Me

                Dim destFolder As New FtpFolder(connection)
                Dim destination As AbstractFolder = _
                destFolder.GetFolder(objGUIDSTLOC.dsGUIDSTLOC.Tables(“GUIDSTLOC”).Rows(intLOC).Item(“DSTPTH”).ToString)

                aDirs = System.IO.Directory.GetDirectories(strFolder)
                For i = 0 To aDirs.GetUpperBound(0)
                    Dim source As AbstractFolder = New DiskFolder(aDirs(i))
                    source.CopyTo(events, Nothing, destination, True)
                Next

                aFiles = System.IO.Directory.GetFiles(strFolder)
                For i = 0 To aFiles.GetUpperBound(0)
                    Dim source As AbstractFile = New DiskFile(aFiles(i))
                    source.CopyTo(events, Nothing, destination, True)
                Next

            Catch ex As Exception
                boolError = True
                dgvProgress.Rows(dgvProgress.Rows.Count – 1).Cells(1).Value = “Failure”
                MessageBox.Show(ex.Message, “Distribution FTP”, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Finally
                If Not connection Is Nothing Then
                    If Not boolError Then
                        dgvProgress.Rows(dgvProgress.Rows.Count – 1).Cells(1).Value = “Finished”
                    End If

                    ‘ Unsubscribe from events.
                    If strOption = “S” Then
                        RemoveHandler connection.CertificateReceived, AddressOf OnCertificateReceived
                    End If
                    RemoveHandler events.ByteProgression, AddressOf OnByteProgression
                    RemoveHandler events.ItemException, AddressOf OnItemException

                    connection.CloseConnections()
                    connection.TraceWriter.Close()
                    connection.Dispose()
                    connection = Nothing
                    boolError = False
                End If
            End Try
        End Sub

        Private Sub OnCertificateReceived(ByVal sender As Object, ByVal e As CertificateReceivedEventArgs)
            Dim sb As New StringBuilder
            Dim result As DialogResult

            ‘ The Status argument property tells you if the server certificate was accepted
            ‘ based on the VerificationFlags you provided.
            If e.Status <> VerificationStatus.ValidCertificate Then
                sb.Remove(0, sb.Length)
                sb.Append(“The server certificate is invalid: “)
                sb.Append(e.Status.ToString)
                sb.Append(vbCrLf)
                sb.Append(e.ServerCertificate.ToString())
                sb.Append(vbCrLf)
                sb.Append(vbCrLf)
                sb.Append(“Do you want to accept this certificate anyway?”)
                result = MessageBox.Show(sb.ToString, “Distribution”, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

                ‘ 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.
                If result = Windows.Forms.DialogResult.Yes Then
                    e.Action = VerificationAction.Accept
                End If
            End If
        End Sub

        Private Sub OnByteProgression(ByVal sender As Object, ByVal e As ByteProgressionEventArgs)
            ‘ Update the form’s progress bar.
            pbProgress.Value = e.AllFilesBytes.Percent
        End Sub

        Private Sub OnItemException(ByVal sender As Object, ByVal args As ItemExceptionEventArgs)
            Dim sb As New StringBuilder
            Dim result As New DialogResult

            sb.Remove(0, sb.Length)
            sb.Append(args.Exception.GetType().Name)
            sb.Append(” error with “)
            sb.Append(args.CurrentItem.FullName)
            sb.Append(vbCrLf)
            sb.Append(“Error = “)
            sb.Append(args.Exception.Message.ToString)
            sb.Append(vbCrLf)
            sb.Append(vbCrLf)
            sb.Append(“How would you like to proceed?”)
            result = MessageBox.Show(sb.ToString, “Distribution”, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question)
            If result = Windows.Forms.DialogResult.Abort Then
                args.Action = ItemExceptionAction.Abort
            ElseIf result = Windows.Forms.DialogResult.Ignore Then
                args.Action = ItemExceptionAction.Ignore
            Else
                args.Action = ItemExceptionAction.Retry
            End If
        End Sub

     Thanks for you help,

    Rodney

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Rodney (had 6118 views)

    User (Old forums)
    Member
    Post count: 23064

    Can you paste the complete exception stack trace here, including the inner exception stack?

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by André (had 392 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi, Andre

    Here is the Exception Stack trace…

       at Xceed.FileSystem.FileSystemItem.CopyTo(FileSystemEvents events, Object userData, AbstractFolder destinationFolder, Boolean replaceExistingFiles)
       at Distribution.FTP_Files(String strFolder, String strOption) in C:\PVCSUSER\GUISRC\DOTNET_WINFORMS\Applications\iCoreGUIDistributionUtility\Distribution.vb:line 382

    Here is the InnerException.Message…

    Accessing AsyncResult without prior call to Attach.

    Here is the InnerException Stack trace…

       at Xceed.Ftp.Engine.BaseFtpCommand.get_AsyncResult()
       at Xceed.Ftp.Engine.FtpDataConsumerCommand.AcquireDataStream(Int32 timeout)
       at Xceed.Ftp.FtpClient.GetUploadStream(String remoteFilename, Boolean append)
       at Xceed.Ftp.FtpFile.OpenWriteAlways(Boolean overwrite, FileShare share)

     Hopefully, I’ve provided all you need.

    If not, let me know and I’ll try to get what you need.

    Thanks for you help!

    Rodney

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Rodney (had 588 views)

    User (Old forums)
    Member
    Post count: 23064

    Since this is an implicit ssl connection, could you set the TraceWriter property so we can get a log of the communication with the server?  We want to verify that the DataChannel is in fact encrypted.

    FtpClient.TraceWriter = new StreamWriter( @”D:\ftp.log”, true );

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by André (had 272 views)

    User (Old forums)
    Member
    Post count: 23064

    Here is a tracewriter log.

    After the first file timed out I replied Ignore to allow the FTP to proceed. After the second file timed out I replied Abort to quit.

     Connected to xx.xxx.xxx.xx:990 on 1/14/2009 @ 3:47:43 PM
    < 220-FileZilla Server version 0.9.29 beta
    < 220-written by Tim Kosse (Tim.Kosse@gmx.de)
    < 220 Please visit http://sourceforge.net/projects/filezilla/
    > USER xxxxxxx
    < 331 Password required for xxxxxxx
    > PASS *****
    < 230 Logged on
    > PWD
    < 257 “/” is current directory.
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > TYPE A
    < 200 Type set to A
    > PASV
    < 227 Entering Passive Mode (xx,xxx,xxx,xx,12,180)
    > LIST
    Data connection established with xx.xxx.xxx.xx:3252 on 1/14/2009 @ 3:47:46 PM
    < 550 PROT P required
    > CWD /test/Folder11
    < 426 Connection closed; transfer aborted.
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > TYPE I
    < 250 CWD successful. “/test/Folder11” is current directory.
    > PASV
    < 200 Type set to I
    < 227 Entering Passive Mode (xx,xxx,xxx,xx,12,181)
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > TYPE A
    < 200 Type set to A
    > PASV
    < 227 Entering Passive Mode (xx,xxx,xxx,xx,13,104)
    > LIST
    Data connection established with xx.xxx.xxx.xx:3432 on 1/14/2009 @ 3:48:38 PM
    < 550 PROT P required
    > CWD /test/Folder11
    < 426 Connection closed; transfer aborted.
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > CWD /test/Folder11
    < 250 CWD successful. “/test/Folder11” is current directory.
    > TYPE I
    < 250 CWD successful. “/test/Folder11” is current directory.
    > PASV
    < 200 Type set to I
    < 227 Entering Passive Mode (xx,xxx,xxx,xx,13,110)
    > QUIT
    Disconnected from xx.xxx.xxx.xx:990 on 1/14/2009 @ 3:49:11 PM

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Rodney (had 533 views)

    User (Old forums)
    Member
    Post count: 23064

    There seems to be the a bug with the implicit connection when using FtpConnection.  We are working on a new version that should be released sometime in february 2009, and which does not reproduce this problem.

    Meanwhile, you can either make an explicit connection, or use FtpClient.

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by André (had 277 views)

    User (Old forums)
    Member
    Post count: 23064

    I changed my code to use the FTPClient instead of FTPConnection and it worked wonderfully!

    Thanks a lot for your help.

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Rodney (had 5125 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.