ReceiveFTPFile keeps failing in ver 5.40

Just starting out? Need help? Post your questions and find answers here.
Randy Walker
Addict
Addict
Posts: 1170
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

ReceiveFTPFile keeps failing in ver 5.40

Post by Randy Walker »

Is it me? Usually is. No matter what I try I cannot get ReceiveFTPFile to to return positive when it downloads a specific file. I even created a loop to make 3 attempts and it still fails. What could I possibly be doing wrong? I know it is connecting ok because it always gives me that "Failed 3 times..." message. Here is my code:

Code: Select all

InitNetwork()
If OpenFTP(6, "ftp.Domain.com", USER$,FTPassword$,#True)
  ;ForEach fileList()
    ;f$ = fileList()
    f$ = "CUSTOMER.ARC"
    Debug f$
    If FindString(LCase(f$),"customer.arc",#PB_String_NoCase)
      cDate = GetFileDate(f$,#PB_Date_Modified)
      ;          MessageRequester("Need Update", "Will attempt customer file download", #MB_OK|#MB_ICONINFORMATION)
    EndIf
    ;           Debug cDate
    If LCase(f$) = "make1log.ex_"
      ; NEW VERSION UPDATE IS READY FOR ONELOOK (pending re-development)
    EndIf
    bad = #False ; TRUE if ReceiveFTPFile fails 3 times
    attempt = 0
    Repeat
      attempt + 1
      ;SetGadgetText(#FTPstatus_0,f$+" download attempt #"+Str(attempt))
      RecieveFailure = #False
      If CheckFTPConnection(6)
        If ReceiveFTPFile(6,f$,f$)
          If FindString(LCase(f$),"customer.arc",#PB_String_NoCase)
            If cDate <> GetFileDate(f$,#PB_Date_Modified)
              cust = #True
            Else
              cust = #False
            EndIf
          EndIf
        Else
          Delay(800)
          RecieveFailure = #True
        EndIf
        If attempt > 2 ;will attempt 3 times
          bad = #True
          badboy$ = f$
          Break
        EndIf
      EndIf
    Until bad = #True  Or RecieveFailure = #True ;abandon retry if success or fail 3 times.
  ;Next
  If bad
    MessageRequester("Download Failed", "AutoFTP Failure -- Tried 3 times and could not perform "+badboy$+" download.", #MB_OK|#MB_ICONWARNING)
  EndIf
  CloseFTP(6)
Else
  ;SetGadgetText(#FTPstatus_0,"Cannot connect To server")
  ; Download unable to connect.
  MessageRequester("FTP problem","Could not connect To server")
EndIf
The really goofy thing is... When I check my local directory, the new file is there, so the ReceiveFTPFile is working. Just not reporting positive when it is successful. Maybe a bug but I cannot use any other PB version to test that theory, because my code gets broken in a gazillion places and impossible to fix all the problems it creates.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Quin
Addict
Addict
Posts: 1155
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by Quin »

Pretty sure this has to be a PB bug, the FTP lib has seen a major update since 5.4.
Philo
New User
New User
Posts: 1
Joined: Sat Nov 01, 2025 8:00 am

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by Philo »

You have a typo in one of your binary variables:

Code: Select all

RecieveFailure
instead of

Code: Select all

ReceiveFailure
However, since you are using it consistently, I cannot see how this would stop your code from working.
User avatar
jacdelad
Addict
Addict
Posts: 2046
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by jacdelad »

Niiiiiiice catch, Philo! Another victim of DisableExplicit.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 507
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by Mindphazer »

jacdelad wrote: Sat Nov 01, 2025 10:13 am Niiiiiiice catch, Philo! Another victim of DisableExplicit.
As Philo said, the variable RecieveFailure is used within the whole code, and ReceiveFailure is not used at all. So in this case EnableExplicit would not have thrown an error
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
jacdelad
Addict
Addict
Posts: 2046
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by jacdelad »

Oh, didn't see that.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
infratec
Always Here
Always Here
Posts: 7704
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by infratec »

Time to update PB, or ... try my libcurl.pbi
Last edited by infratec on Sun Nov 02, 2025 11:17 am, edited 1 time in total.
normeus
Enthusiast
Enthusiast
Posts: 485
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by normeus »

Try this example by TerryHough:

viewtopic.php?p=354215#p354215


(Notice how a delay is used to see if the file has started to download. )

Code: Select all

.........
  ReceiveFTPFile(Connect, GetFilePart(Filename), Filename, 1) 
; repeatdelay3=3
  Repeat 
    Delay(10) 
;    repeatdelay3=repeatdelay3-1
  Until FTPProgress(Connect) = #PB_FTP_Started ; or  repeatdelay3 < 1
........
Of course you can do that delay a couple of times then exit with an error if nothing happened.

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
Randy Walker
Addict
Addict
Posts: 1170
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: ReceiveFTPFile keeps failing in ver 5.40

Post by Randy Walker »

Philo wrote: Sat Nov 01, 2025 8:26 am You have a typo in one of your binary variables:

Code: Select all

RecieveFailure
instead of

Code: Select all

ReceiveFailure
However, since you are using it consistently, I cannot see how this would stop your code from working.
Only 3 occurrences of that "RecieveFailure" variable and they only exist inside that one procedure. PB does not penalize for bad spelling in variable names so the typo is totally moot. Enableexplicit doesn't do spell checking either so again, moot point.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply