Page 1 of 2
FTPPutFile() requires too minutes to upload
Posted: Sun Oct 26, 2025 3:50 pm
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
Re: FTPPutFile() requires too minutes to upload
Posted: Mon Oct 27, 2025 2:47 pm
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.
Re: FTPPutFile() requires too minutes to upload
Posted: Mon Oct 27, 2025 8:14 pm
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)
Re: FTPPutFile() requires too minutes to upload
Posted: Mon Oct 27, 2025 8:37 pm
by karinha
Re: FTPPutFile() requires too minutes to upload
Posted: Mon Oct 27, 2025 8:38 pm
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.
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 7:02 am
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...
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 7:32 am
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.
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 10:20 am
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?
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 10:42 am
by Enrico Maria Giordano
The IFs you have already using are not enough?
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 10:52 am
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.
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 11:02 am
by Enrico Maria Giordano
Search the forum for alternative functions for FTP.
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 11:28 am
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.
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 2:35 pm
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
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 3:27 pm
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.
Re: FTPPutFile() requires too minutes to upload
Posted: Tue Oct 28, 2025 3:35 pm
by Enrico Maria Giordano
Almost instantly.