FTPPutFile() requires too minutes to upload

marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

FTPPutFile() requires too minutes to upload

Post by marzio »

hi at all.
I have inserted a function into my programs that uploads a text file to an FTP server which I then access to consult some usage information.

lUpLoad := FTPPutFile( oFtp:hFTP, cFile, cWhere + cFile, FTP_TRANSFER_TYPE_BINARY, 0 )

The function runs when the program closes, but it takes too long (many minutes) to upload, so the program stays active in background.
Once the first upload is complete, subsequent uploads take a few seconds.

Is it possible to prevent the first upload from taking that long?
thanks
User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: FTPPutFile() requires too minutes to upload

Post by Enrico Maria Giordano »

Can you provide a reduced and self-contained sample to reproduce the problem, please? We also need a test FTP account to make a test.
marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

Re: FTPPutFile() requires too minutes to upload

Post by marzio »

Thank you so much, Enrico, for your help.
I created a minimal function, but I can't provide you with a test FTP account. I'm staying with a friend who has an account at aruba.it.
Could my problem be due to security restrictions on the Aruba server? Or to the PC firewalls?
Every time I change the program's execution folder on my PC, uploading the file via FTP takes this interminable time.
The name of the file being uploaded is encrypted with the CharOdd() and CharEven() functions. Could this cause security issues when accessing it?
If you have any suggestions or modifications to the function, you're welcome. In the meantime, I'd better try to test it by removing the encryption and making some other changes.

UpLoadFile("File.txt", "ecc.it/users/")


FUNCTION UpLoadFile(cFile, cWhere)

LOCAL oInternet, oFtp, lUpLoad := .f.

oInternet := tInternet():New()

IF oInternet:hSession != 0
oFtp := tFtp():New("ftp.ecc.it", oInternet, cUser, cPass, 134217728)

IF oFtp:hFTP != 0
lUpLoad := FTPPutFile( oFtp:hFTP, cFile, cWhere + cFile, FTP_TRANSFER_TYPE_BINARY, 0 ) // PUNTO CRITICO CHE IMPIEGA MINUTI LA 1° VOLTA !
oFtp:End()
ENDIF
oInternet:End()
ENDIF

Return(lUpLoad)
User avatar
karinha
Posts: 8720
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: FTPPutFile() requires too minutes to upload

Post by karinha »

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: FTPPutFile() requires too minutes to upload

Post by Enrico Maria Giordano »

I have an FTP account on Aruba too. I tried your sample with my account. The first time I run it, Windows Firewall asked me to allow the EXE, then it worked fine without any delay.
marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

Re: FTPPutFile() requires too minutes to upload

Post by marzio »

Enrico,
Try answering "no" to the firewall permission. You may need to rename the folder.
a good portion of users answer "no"

Thanks Karinha for the suggested posts. I'll study them...
User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: FTPPutFile() requires too minutes to upload

Post by Enrico Maria Giordano »

If you answer no to the firewall then the program FTP communication will not work at all. That is normal and expected behavior.
marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

Re: FTPPutFile() requires too minutes to upload

Post by marzio »

Of course, if I answer "no" or "cancel," it won't load anything, but that's when it crashes. The function I posted should intercept the firewall's "no" and not launch the FTPPutFile() function, and it keeps doing that every time.
How can I verify that the firewall has not granted me permission?
marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

Re: FTPPutFile() requires too minutes to upload

Post by marzio »

Maybe none of those IFs control the firewall.
I need to make sure that if someone doesn't give permission, the function FTPPutFile() isn't launched.
marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

Re: FTPPutFile() requires too minutes to upload

Post by marzio »

Thanks Enrico.
I'll do it.
I just verified that it's the function FTPPutFile() itself that triggers the firewall request, so it's not possible to exclude the function call with an IF statement.
User avatar
Enrico Maria Giordano
Posts: 9054
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: FTPPutFile() requires too minutes to upload

Post by Enrico Maria Giordano »

I just tried this test below: it show a little dialog with .F. when the program is blocked by the firewall.

Code: Select all | Expand

#include "Fivewin.ch"


FUNCTION MAIN()

    ? UPLOADFILE( "TEST.PRG", "emagsoftware.it/test/" )

    RETURN NIL


#define FTP_TRANSFER_TYPE_BINARY 2


STATIC FUNCTION UPLOADFILE( cFile, cWhere )

    LOCAL oInternet, oFtp, lUpLoad := .F.

    oInternet = TInternet():New()

    IF oInternet:hSession != 0
        oFtp = TFtp():New( "ftp.emagsoftware.it", oInternet, "userid", "password" )

        IF oFtp:hFTP != 0
            lUpLoad = FTPPUTFILE( oFtp:hFTP, cFile, cWhere + cFile, FTP_TRANSFER_TYPE_BINARY, 0 )
            oFtp:End()
        ENDIF

        oInternet:End()
    ENDIF

    RETURN lUpload
marzio
Posts: 193
Joined: Wed Apr 04, 2007 6:54 am

Re: FTPPutFile() requires too minutes to upload

Post by marzio »

How long does it take for the function to return false? Because that's the critical point; it makes me wait for many minutes.
Post Reply