Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3k views
in .NET FTP by (1.1k points)
been using ediFTPnet/PRO for a few weeks now, with no problems at all.

However, there seems to be no way to tell when a network is unreachable. The code errors out with an unhandled NullReferenceException:

Event Type: Error
Event Source: .NET Runtime 2.0 Error Reporting
Event Category: None
Event ID: 5000
Date: 10/4/2007
Time: 10:15:22 AM
User: N/A
Computer: CLP101732
Description:
EventType clr20r3, P1 clp_iris.exe, P2 1.0.2826.27445, P3 46fc0f68, P4 edtftpnetpro, P5 4.2.0.0, P6 46957031, P7 1521, P8 0, P9 system.nullreferenceexception, P10 NIL.



i have a try block like this:

    Dim connected As Boolean = False

        Try

            If CertificateExists() Then
                    'connect to FTP
                    If sftp Is Nothing Then
                        sftp = New SecureFTPConnection
                    End If
                    
                    'set settings omitted

                    sftp.Connect()

                    connected = True


                End If
            Else

                 MessageBox.Show("The Certificate required for this application - clpftp.cer - is not installed", _
                "Certificate Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        Catch ex As System.NullReferenceException
            connected = False

            logger.ErrorException("Error", ex)

        Catch ex As Exception

            logger.ErrorException("Error", ex)

            connected = False

        Finally

 
        End Try

        Return connected


If i pull my network plug and try to connect, the application throws a NullReferenceException with an object does not exist. It does not fall to the catch. if i am in debug mode, the code stops on this line:

sftp.Connect()

and shows me the NullReferenceException. it never drops to either of the Catch statements

Its as if the sftp object itself is destroyed when it cannot reach the network.

I got around this by coding this function:


 Private Function CanSeeFTP() As Boolean

        Dim client As New TcpClient()
        Dim ret As Boolean = False

        Try
            client.Connect(Me.uxFTPServer.Text, Me.uxFTPPort.Text)
            If client.Connected Then
                ret = True
                client.Client.Disconnect(False)
            Else
                ret = False
            End If

        Catch ex As Exception
            ret = False
        End Try
        Return ret

    End Function


and adding an If CanSeeFTP() Then prior to connecting:

      If CertificateExists() Then
                If CanSeeFTP() Then
                    'connect to FTP
                    If sftp Is Nothing Then
                        sftp = New SecureFTPConnection
                    End If


Is there any functionality built into ediFTPnet/PRO to notify me that the server is unreachable?

4 Answers

0 votes
by (162k points)
Can you enable logging at the All level and post the relevant parts of the log?

Also, in the debugger at the line "sftp.Connect()", what is the value of the sftp variable?
0 votes
by (1.1k points)
I don't use any logging at all.

so, when i enabled logging, it did fall to my catch routine.

prior to the connect, here is the sftp.value:

EnterpriseDT.Net.Ftp.SecureFTPConnection

while connecting to a non-existent network here is the log:

DEBUG [SSLFTPClient] 8 Oct 2007 09:12:15.656 : Connecting to 204.130.8.3:990
DEBUG [HostNameResolver] 8 Oct 2007 09:12:15.656 : 204.130.8.3 resolved to 204.130.8.3
DEBUG [SSLFTPControlSocket] 8 Oct 2007 09:12:15.656 : waitOnShutdownSSL=True
DEBUG [ExFTPControlSocket] 8 Oct 2007 09:12:15.656 : Connecting directly to ftp-server 204.130.8.3:990
ALL [AsyncResult] 8 Oct 2007 09:12:15.672 : WaitOne begin: -1 0
DEBUG [AsyncResult] 8 Oct 2007 09:12:15.719 : A socket operation was attempted to an unreachable host
ALL [AsyncResult] 8 Oct 2007 09:12:15.719 : Notify setting completed: A socket operation was attempted to an unreachable host 0
ALL [AsyncResult] 8 Oct 2007 09:12:15.719 : Notify setting wait: 0
ALL [SecureSocket] 8 Oct 2007 09:12:15.719 : Notify: SecureSocket.OnConnect
ALL [SecureSocket] 8 Oct 2007 09:12:15.719 : Notify: SecureSocket.OnConnect
ALL [AsyncResult] 8 Oct 2007 09:12:15.719 : WaitOne end: True 0


So i need to enable logging for the Try-Catch to work? this application goes to external clients and i really don't want to have to manage another log file. I think i will stay with my CanSeeFTP() function
0 votes
by (162k points)
Enabling logging will not affect try-catch - it just gives us a better idea of what is going on.
0 votes
by (1.1k points)
i thought that was the case, however, the only way i can get it to fall to catch is to enable logging. if logging is off, it stops at the connect statement

Categories

...