Home Forums .NET libraries Xceed SFTP/FTP for .NET To throw FTP connection exception

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

    Hi,

    We use Xceed FTP to connect to FTP.
    While connecting to our client’s FTP we sometimes never get response for a while from the server. so we decided to terminate the connection process after few second(eg:20 seconds).which is the best place to throw an exception after waiting for connection response for few seconds , in our code?

    We have  a method called Connect() in this class which we call from the App to connect.

    Public

    Function Connect() As Boolean


    Try


    _oAsyncFtpClient =

    Nothing


    _oAsyncFtpClient =

    New AsyncFtpClient()


    _oAsyncFtpClient.SynchronizingObject =

    CType(_oSychronizingObject, System.ComponentModel.ISynchronizeInvoke)


    _bAllFilesSent =

    False


    _bAllFilesReceived =

    False


    _sLog =

    “”


    _bWasError =

    False

    If _sProxyAddress.Length = 0 Then


    _oAsyncFtpClient.Proxy =

    Nothing


    Else


    _oAsyncFtpClient.Proxy =

    New HttpProxyClient(_sProxyAddress, _iProxyPort, _sProxyUserName, _sProxyPassword)


    End If

    If _bOptionSecureImplicit Then


    _oAsyncFtpClient.BeginConnect(_sHostAddress, _iHostPort, AuthenticationMethod.Tls, VerificationFlags.None,

    Nothing, _


    New AsyncCallback(AddressOf Me.ConnectCompleted), Nothing)


    Else


    _oAsyncFtpClient.BeginConnect(_sHostAddress, _iHostPort,

    New AsyncCallback(AddressOf Me.ConnectCompleted), Nothing)


    End If


    Catch x As Exception


    HandleExceptions(

    “An error occured while trying to connect to host. “ & “Function:Connect”, x, False)


    End Try


    End Function

    —————————————————————————————————————————————————————————————————–

    Private Sub ConnectCompleted(ByVal asyncResult As IAsyncResult)


    Try


    _oAsyncFtpClient.EndConnect(asyncResult)

    if _bOptionSecureImplicit Then


    Authenticate()

    Else


    Login()

    End If


    Catch x As Exception


    HandleExceptions(

    “An error occured while trying to connect to host. “ & “Function:ConnectCompleted”, x, False)


    End Try


    End Sub

     

     

    Your  help is much appreciated

    Melbin

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

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     Can anyone help on my question?

    Thanks

    Melbin

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

    User (Old forums)
    Member
    Post count: 23064

    Well, I wouldn’t think you would throw the exception from either of those methods (unless you got a legitimate exception) because you want to wait UP TO 20 seconds.

     That tells me that it must be an asynchronous call to the connect method, so you probably just need a timer someplace in your main thread. Once 20 seconds have passed, check on the status of your Ftp connection, if it’s not established, then throw your custom timeout exception (or Xceed.Ftp.FtpException).

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

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