Page 1 of 1

ReceiveFTPFile keeps failing in ver 5.40

Posted: Tue Oct 28, 2025 11:08 pm
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.

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Wed Oct 29, 2025 2:04 am
by Quin
Pretty sure this has to be a PB bug, the FTP lib has seen a major update since 5.4.

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sat Nov 01, 2025 8:26 am
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.

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sat Nov 01, 2025 10:13 am
by jacdelad
Niiiiiiice catch, Philo! Another victim of DisableExplicit.

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sat Nov 01, 2025 10:57 am
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

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sat Nov 01, 2025 11:32 am
by jacdelad
Oh, didn't see that.

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sat Nov 01, 2025 11:51 am
by infratec
Time to update PB, or ... try my libcurl.pbi

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sat Nov 01, 2025 5:59 pm
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.

Re: ReceiveFTPFile keeps failing in ver 5.40

Posted: Sun Nov 02, 2025 12:16 am
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.