0 votes
by (480 points)
edited

Hello,

Am using the FTP.Download() method to download contents from a remote folder Apparently the connection is initiated just fine (by reading the logs) but it always fails at a point in time when reading folder contents. My remote folder has 3000 files that contains a few more folders and other files inside them. So what happens it that it reads about 490 files (seen from FilesProcessed event) and then it pops this message.

Here is my log https://www.dropbox.com/s/uouu96kq78mtvju/logs.txt

As far as I could see, it always fails on "Command: CWD /common/battlefield 2/mods/bf2/Levels/OperationHarvest" - folder

My server runs ProFTPd but not sure if that should matter much Code I use (.net 3.5)

Imports Rebex
Imports Rebex.IO
Imports Rebex.Net
Imports Rebex.Security.Certificates
Imports System.IO

Public Class Form1
    Private FTP As Ftp
    Dim ip As String = "ip"
    Dim port As Integer = "21"
    Dim username As String = "username"
    Dim password As String = "password"
    Dim ssltrue As Rebex.Net.SslMode = SslMode.Explicit
    Dim counter As Integer

    Private Sub ButtonGreen1_Click(sender As System.Object, e As System.EventArgs) Handles ButtonGreen1.Click
        Download()
    End Sub

    Public Sub Download()
        If Not Connect() Then
            Return
        End If

        Try
            SetState(True)
            If Directory.Exists("download") = False Then
                Directory.CreateDirectory("download")
            End If
            FTP.ChangeDirectory("/common/")
            FTP.Download("battlefield 2", "download", TraversalMode.Recursive, TransferMethod.Copy, ActionOnExistingFiles.OverwriteDifferentSize)
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Disconnect()
            SetState(False)
        End Try
    End Sub

    Private Sub TransferProgressChanged(ByVal sender As Object, ByVal e As FtpTransferProgressChangedEventArgs)
        PreloaderProgressBar1.Progress = e.ProgressPercentage
        If PreloaderProgressBar1.Progress = 100 Then
            ButtonGreen1.Text = "Start Download"
        Else
            ButtonGreen1.Text = "Downloading..."
        End If
        Label4.Text = "Files processed " & e.FilesProcessed
        Label5.Text = "Speed " & ThreeNonZeroDigits(BytesTO(e.BytesPerSecond, convTo.KB)) & " KB\s"
        Label6.Text = "Total downloaded " & ThreeNonZeroDigits(BytesTO(e.BytesTransferred, convTo.MB)) & " MB"
        ' process any application events to prevent the window from freezing
        Application.DoEvents()
    End Sub

    Private Sub Traversing(ByVal sender As Object, ByVal e As FtpTraversingEventArgs)
        Label3.Text = "Total files " & e.FilesTotal
        Select (e.TraversingState)
            Case TraversingState.HierarchyRetrieving
                ButtonGreen1.Text = "Retrieving hierarchy..."
                Exit Select
        End Select
        ' process any application events to prevent the window from freezing
        Application.DoEvents()
    End Sub

    Private Sub ButtonBlue1_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBlue1.Click
        If Connect() Then
            Disconnect()
        End If
        End
    End Sub

    Private Function Connect() As Boolean
        Try
            Cursor = Cursors.WaitCursor

            FTP = New Ftp
            FTP.Settings.SslAcceptAllCertificates = True
            Dim passive As Boolean = CheckBox1.Checked
            FTP.Passive = passive
            Dim largebuffers As Boolean = CheckBox2.Checked

            FTP.LogWriter = New Rebex.FileLogWriter(Application.StartupPath & "\connection_log.log", Rebex.LogLevel.Debug)

            FTP.Settings.UseLargeBuffers = largebuffers
            FTP.Connect(ip, port, ssltrue)
            FTP.Login(username, password)

            AddHandler FTP.TransferProgressChanged, AddressOf TransferProgressChanged
            AddHandler FTP.Traversing, AddressOf Traversing
            Return True
        Catch x As Exception
            MsgBox(x)
            Return False
        Finally
            Cursor = Cursors.Arrow
        End Try
    End Function

    Private Sub Disconnect()
        FTP.Disconnect()
        FTP.Dispose()
        FTP = Nothing
    End Sub

    Private Sub SetState(ByVal transferring As Boolean)
        If transferring Then
            ' enable/disable buttons
            ButtonGreen1.Enabled = False
            CheckBox1.Enabled = False
            CheckBox2.Enabled = False
        Else
            ButtonGreen1.Enabled = True
            CheckBox1.Enabled = True
            CheckBox2.Enabled = True
        End If
    End Sub
Applies to: Rebex FTP/SSL

2 Answers

0 votes
by (144k points)
edited

According to the log, it looks like it doesn't fail on "CWD /common/battlefield 2/mods/bf2/Levels/OperationHarvest", but rather on waiting for the response to "PASV" command soon afterwards.

It's useful to understand that:

  1. The PASV command is used when initializing a data connection to the server.
  2. All the PASV commands are essentially identical.
  3. When the server receives the PASV command, it doesn't know yet whether the client is about to ask for a directory listing, file upload or file download.

So what we see in the log is a lot of successful PASV commands, and then one that resulted in a connection failure. My guess is that the server was unable to start listening for incoming data connection for some reason at that point, and failed as a result of this. However, because we only have a client-side log, it's impossible to tell for sure.

Would it be possible to look into the server log and see whether there is anything that might help us to determine what was actually going on?

by (480 points)
edited

so managed to see over the server logs and there are not transfer problems now then, I've noticed that if I set sslmode to none it works great but this is not what I want since I want my connection to be secured also noticed that filezilla downloads the folder with no prob, but noticed filezilla starts the download right when I drop the folder from my remote location so this means that there is a prob in my settings somehow any idea?

by (144k points)
edited

I'm afraid I don't understand what you mean by "filezilla starts the download right when I drop the folder from my remote location", please explain. In any case, would it be possible to upload FileZilla's log as well? By comparing it with Rebex FTP log, we might be able to spot some differences and let you know which settings to change.

0 votes
by (480 points)
edited

fixed by moving to sftp protocol anyway as a small notice, if you disable ssl mode it will work better in ftp protocol

by (144k points)
edited

Actually, moving to SFTP is often a good solution when dealing with firewall issues caused by FTP/SSL - see this answer for other recommended actions.

...