Re: FTP CLIENT work in CABLE does not work on ADSL ?

Giganews Newsgroups
Subject: Re: FTP CLIENT work in CABLE does not work on ADSL ?
Posted by:  Remy Lebeau (Indy Team) (
Date: Fri, 10 Nov 2006

"Edward. Z. F. M." <edward.z.f…> wrote in message

> What is wrong in my code ?

From a socket perspective, there is no difference whatsoever between Cable
and DSL (or dialup, for that matter).  A network connection is a network
connection, regardless of the underlying hardware.

> on my machine(CABLE MODEM CONECTION), and all work
> fine, but in another machine (ADSL CONNECTION) the code
> does not work.

Just saying that it doesn't work says nothing at all about the actual
problem you are having.  Please be more specific.  Where exactly does it
fail?  Are there any error messages?

>        try
>        {
>          IdFTPClient->Connect();
>        }
>        __except(true)

Do not use SEH exception handlers to catch VCL exceptions.  Use C++'s own
'catch' handler instead:

    catch(const Exception &)

>          IdFTPClient->Disconnect();

You do not need to call Disconnect() if Connect() throws an exception.
Connect() will handle that internally.

You also are not using exception handling very effectively, either.  For one
thing, when an exception occurs, you are disconnecting and then moving on to
the next operation, which will throw a different exception, which you catch
and move on to the next operation, and so on.  Also, rather than having a
separate handler for each individual operation, wrap all of the operations
inside a single handler instead, especially since they all do the same thing
(disconnect the socket) when an exception is thrown, so you don't need to
duplicate that over and over.

>                IdFTPClient->Put(Dir + Arq, Arq, false);

You are passing the wrong folder to Put().  The first parameter is the
SOURCE file from your local machine, but you are specifying the REMOTE
folder that you got from RetrieveCurrentDir() instead.

For that matter, you are unconditionally connecting to the server, but then
calling Put() only if the local file exists.  So there is no point in
connecting to the server at all if the local file does not exist.

Try the following code instead:

    if( FileExists(Arq) )
        IdFTPClient->Host = "";
        IdFTPClient->Username = "U";
        IdFTPClient->Password = "P";
        IdFTPClient->Port = 21;
        IdFTPClient->TransferType = ftBinary;

                IdFTPClient->Put(Arq, Arq, false);
            __finally {
        catch(const Exception &)
            // do something ...



In response to

FTP CLIENT work in CABLE does not work on ADSL ? posted by Edward. Z. F. M on Fri, 10 Nov 2006