Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.2k views
in .NET FTP by
Hello all,

I have two pieces of code which give me strange exceptions.

1:
Dim Items() As FTPFile
Try
Items = fc.DirDetails(url.AbsolutePath.Substring(1))
Catch ex As Exception
'Retry
Items = fc.DirDetails(url.AbsolutePath.Substring(1))
End Try

Once in a while this code seems to fail, with an exception: Transfer complete.
Stack trace:
at EnterpriseDT.Net.Ftp.FTPControlSocket.ValidateReply(FTPReply reply, String expectedReplyCode)
at EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocketPASV()
at EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocket(FTPConnectMode connectMode)
at EnterpriseDT.Net.Ftp.FTPClient.Dir(String dirname, Boolean full)
at EnterpriseDT.Net.Ftp.FTPClient.DirDetails(String dirname)


2:
Try
fc.Get(SaveTo & "\" & fileOrFolder.Name, url.AbsolutePath.Substring(1) & "/" & fileOrFolder.Name)
Catch ex As Exception
'Retry
If File.Exists(SaveTo & "\" & fileOrFolder.Name) Then
File.Delete(SaveTo & "\" & fileOrFolder.Name)
End If
'Reget
fc.Get(SaveTo & "\" & fileOrFolder.Name, url.AbsolutePath.Substring(1) & "/" & fileOrFolder.Name)
End Try

Once in a while also this code seems to fail, with an exception: Entering Passive Mode (213,19,161,142,12,80).
Stack trace:
at EnterpriseDT.Net.Ftp.FTPControlSocket.ValidateReply(FTPReply reply, String[] expectedReplyCodes)
at EnterpriseDT.Net.Ftp.FTPClient.InitGet(String remoteFile)
at EnterpriseDT.Net.Ftp.FTPClient.GetBinary(String localPath, String remoteFile)
at EnterpriseDT.Net.Ftp.FTPClient.Get(String localPath, String remoteFile)

What am I doing wrong? Any idea's?
Thanks in advance.

8 Answers

0 votes
by (162k points)
The first is unusual server behaviour, and is possibly fixed in 1.2.1, out today

Hello all,

I have two pieces of code which give me strange exceptions.

1:
Dim Items() As FTPFile
Try
Items = fc.DirDetails(url.AbsolutePath.Substring(1))
Catch ex As Exception
'Retry
Items = fc.DirDetails(url.AbsolutePath.Substring(1))
End Try

Once in a while this code seems to fail, with an exception: Transfer complete.
0 votes
by
The first is unusual server behaviour, and is possibly fixed in 1.2.1, out today


Any word on the second exception?

Also, I found another strange exception: Login with USER first.
Stack trace:
at EnterpriseDT.Net.Ftp.FTPControlSocket.ValidateReply(FTPReply reply, String[] expectedReplyCodes)
at EnterpriseDT.Net.Ftp.FTPClient.Password(String password)
at EnterpriseDT.Net.Ftp.FTPClient.Login(String user, String password)

in this code block:
Private Sub ExecuteFtp(ByVal url As Uri, ByVal SaveTo As String,
ByVal Connect As Boolean, ByRef failures As Boolean)
Try
If Connect Then
ftp.Timeout = 120 * 1000
ftp.RemoteHost = url.Host
ftp.Connect()
ftp.Login(Username, Password)
ftp.TransferType = FTPTransferType.BINARY
End If
......etc

The FTP server used is Microsoft FTP Service (Version 5.0), IIS.

Kind regards,

Davidvl
0 votes
by
I forgot to insert this before ftp.login(user, password). :

ftp.connect()


Jakob :oops:
0 votes
by
Thanks Jakob, I have changed my code.

I still get an exception sometimes though on code example 1. I now get this exception:
Data connection already open; Transfer starting.

On this code:
Dim items() As FTPFile
Try
items = ftp.DirDetails(url.AbsolutePath.Substring(1))
Catch ex As Exception
'Retry
items = ftp.DirDetails(url.AbsolutePath.Substring(1))
End Try

This is the log:
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.038 : 220 net3-nl-iis-35 Microsoft FTP Service (Version 5.0).
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.038 : ---> USER mediamaker.nl
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.138 : 331 Password required for mediamaker.nl.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.138 : ---> PASS ********
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.238 : 230 User mediamaker.nl logged in.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.238 : ---> TYPE I
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.338 : 200 Type set to I.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.338 : ---> SYST
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.439 : 215 Windows_NT version 5.0
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.449 : ---> PASV
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.549 : 227 Entering Passive Mode (213,19,161,142,10,221).
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.659 : ---> LIST
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.679 : ---> PASV
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.759 : 125 Data connection already open; Transfer starting.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:00.859 : 226 Transfer complete.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.523 : 227 Entering Passive Mode (213,19,161,142,10,222).
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.533 : ---> PASV
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.533 : ---> PASV
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.533 : ---> PASV
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.623 : 227 Entering Passive Mode (213,19,161,142,10,226).
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.723 : 227 Entering Passive Mode (213,19,161,142,10,227).
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.853 : ---> LIST
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 11 okt 2005 18:33:03.964 : 125 Data connection already open; Transfer starting.


Can someone please help? Am I doing something wrong or is this a bug?

Thanks in advance very much.

Kind regards,

David van Leerdam
0 votes
by
Any idea's yet? I defined my connection this way:

ftp.Timeout = 120 * 1000
ftp.StrictReturnCodes = False
ftp.RemoteHost = url.Host
ftp.ConnectMode = FTPConnectMode.ACTIVE
ftp.Connect()
ftp.Login(Username, Password)
ftp.TransferType = FTPTransferType.BINARY

What might be going wrong? Unfortunately, the FTP component is very hard to debug for me.
0 votes
by
What might be going wrong? Unfortunately, the FTP component is very hard to debug for me.


Hello all,

I debugged my previously discussed project's code more deeply and discovered a bug which problably caused edtftp's behaviour.

My application runs a variable number of threads that each contain a timer and an ftpclient object. The timer will fire every second and determines whether or not it's time to activate the ftp client and starts a (recursive) download.
Due to a bug in my code, there were situations where the timer eventhandler started downloads in multiple (following) events. So the downloadRecursive() method was called more than once on the same object using the same ftp client.

I think my code works fine now. I still get exceptions though but found out that the InnerException is always an IOException with code 10054 which states a 'Connection reset by peer' error. I currently handle this by quitting, reconnecting and restarting the active download, but I think there are better ways to handle this. Any idea's?

I use this method to determine whether or not it's a 10054 exception:

    Protected Function isConnectionReset(ByVal ex As Exception) As Boolean
        If TypeOf ex Is IOException And Not ex.InnerException Is Nothing AndAlso TypeOf ex.InnerException Is SocketException Then
            Dim se As SocketException = ex.InnerException
            If se.ErrorCode = 10054 Then
                'Connection reset by peer
                Return True
            End If
        End If

        Return False
    End Function


Kind regards,

David van Leerdam
0 votes
by (162k points)
Could be a socket problem as discussed on another thread. Quitting & reconnecting probably gives enough time for another couple to be freed up.

I think my code works fine now. I still get exceptions though but found out that the InnerException is always an IOException with code 10054 which states a 'Connection reset by peer' error. I currently handle this by quitting, reconnecting and restarting the active download, but I think there are better ways to handle this. Any idea's?
0 votes
by
Could be a socket problem as discussed on another thread. Quitting & reconnecting probably gives enough time for another couple to be freed up.

I think my code works fine now. I still get exceptions though but found out that the InnerException is always an IOException with code 10054 which states a 'Connection reset by peer' error. I currently handle this by quitting, reconnecting and restarting the active download, but I think there are better ways to handle this. Any idea's?


This is correct. Calling a delay method did the same trick, which is a much nicer solution. For you convenience, here is the code:

    Private Sub sleep(ByVal millisecondsTimeout As Integer, ByVal keepAlive As Boolean)
        Dim keepAliveSeconds As Integer = millisecondsTimeout / 1000
        Dim pendingMilliseconds As Integer = millisecondsTimeout Mod 1000

        For i As Integer = 1 To keepAliveSeconds
            If keepAlive And Not client Is Nothing Then
                Try
                    If Not client.IsConnected Then
                        reconnect()
                    End If
                    client.NoOperation()
                Catch ex As Exception
                    'Ignore FTP exceptions, it's not that big a deal
                End Try
            End If

            System.Threading.Thread.Sleep(1000)
        Next

        System.Threading.Thread.Sleep(pendingMilliseconds)
    End Sub

Categories

...