[REVIDSED] OpenFtp() only fails -- other clients work fine.

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

[REVIDSED] OpenFtp() only fails -- other clients work fine.

Post by Randy Walker »

[UPDATE 12-02-25] The failure in OpenFTP()is not failure to open the FTP channel. It is a failure in OpenFTP to report succeessful open. (see my last post. viewtopic.php?p=648529#p648529
It actually does Open FTP but fails to return that success value. Gives zero instead.

[Originasl Post] Is there something fundamentally wrong with my OpenFTP command line? It keeps failing to connect. I have 2 FTP clients that both connect fine using same credentials:

Code: Select all

If OpenFTP(0, "ftp.domain.com", USER$,Trim(DeCrypt(FTPassword$)),#True)
I've tried variations, putting the literal username and password in there and same results. OpenFTP just stopped liking me for some unknown reason. Was working. Just don't see what I could be doing wrong. I get no syntax error. It just returns zero every try. I know the #True was not necessary. tried with and without. fails on v5.40, 5.62 and 6.21 in win 11 Pro.
Last edited by Randy Walker on Wed Dec 03, 2025 8:55 am, edited 2 times in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
BarryG
Addict
Addict
Posts: 4273
Joined: Thu Apr 18, 2019 8:17 am

Re: OpenFtp() only fails -- other clients work fine.

Post by BarryG »

No new firewall setting preventing access for your app suddenly? Also, the user name and password can be case-sensitive on FTP. Checked that? Because maybe the server didn't care before but had a change and now requires it. That's all I can think of.
Randy Walker
Addict
Addict
Posts: 1171
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: OpenFtp() only fails -- other clients work fine.

Post by Randy Walker »

Ok, Thanks barryG !!!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
infratec
Always Here
Always Here
Posts: 7712
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFtp() only fails -- other clients work fine.

Post by infratec »

Try PB 6.30 or use ftp://ftp.domain.com
Randy Walker
Addict
Addict
Posts: 1171
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: OpenFtp() only fails -- other clients work fine.

Post by Randy Walker »

BarryG wrote: Mon Dec 01, 2025 8:14 am No new firewall setting preventing access for your app suddenly? Also, the user name and password can be case-sensitive on FTP. Checked that? Because maybe the server didn't care before but had a change and now requires it. That's all I can think of.
Firewall it seems. I am using Comodo Free firewall and it allowed me to flag my ftp site as safe and connection problems seem to be gone now. The Comodo firewall has settings Defender never dreamed of but fortunately defender totally bows out of firewall security because Comodo is there.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy Walker
Addict
Addict
Posts: 1171
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: OpenFtp() only fails -- other clients work fine.

Post by Randy Walker »

infratec wrote: Mon Dec 01, 2025 8:54 am Try PB 6.30 or use ftp://ftp.domain.com
ftp://ftp.domain.com
Interesting thought ifrastec. Thanks!!
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
infratec
Always Here
Always Here
Posts: 7712
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFtp() only fails -- other clients work fine.

Post by infratec »

Randy Walker
Addict
Addict
Posts: 1171
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: OpenFtp() only fails -- other clients work fine.

Post by Randy Walker »

So here is what i determined... I get faldse negative response from OpenFTP() and because the code (Seen below) gave me 3 failures each time, I thought it was actually failing to open and do the ExamineFTPDirectory(0) which turns out was also working:

Code: Select all

  Repeat
    count + 1
    ;Debug count
    ;Debug USER$+"  "+DeCrypt(FTPassword$)
    s$ = DeCrypt(FTPassword$)
    If OpenFTP(0, " ftp://ftp.domain.com", USER$,Trim(DeCrypt(FTPassword$)),#True)
      s$ = ""
      ;Debug "DID HOME LIST CONNECT", 2
      SetGadgetText(#FTPstatus_0,"Connected to Server")
      If CreateFile(10,"C:\ONELOG\Server.dat",#PB_Ascii)
        If ExamineFTPDirectory(0) ; Step thru Server Directory to get file list
          While NextFTPDirectoryEntry(0)
            If FTPDirectoryEntryType(0) = #PB_FTP_File
              entry$ = FTPDirectoryEntryName(0) +" "+ FTPDirectoryEntryDate(0)
              If FindString(entry$,"C:\ONELOG\") = 0
                If FindString(entry$,"pref") = 0  ;not collecting ,pref files.
                  If FindString(Lastfilelist$,entry$) = 0 ; no match means download required
                                                          ;                 ;Debug entry$
                    If FindString(entry$,"CUSTOMER.ARC")
                      ;MessageRequester("Need Update", "Need customer file for latest update", #MB_OK|#MB_ICONINFORMATION)
                      Changes = #True
                    EndIf
                    If FindString(entry$,RegisteredUser$)
                      usrprfs = #True
                    EndIf
                    AddElement(fileList.s())
                    d$ = StringField(entry$,1," ")
                    If FindString(entry$,"C:\ONELOG\") = 0
                      fileList() = d$ ; hold name only for Inv_Home to do download
                    EndIf
                    ;Debug d$, 2
                    ;Debug "ADDED - "+fileList()
                  EndIf
                EndIf
                WriteStringN(10,entry$,#PB_Ascii)
              EndIf
            EndIf
          Wend
          FinishFTPDirectory(0)
          ;Debug "End of Directory", 2
        Else
          MessageRequester("Access Error", "AutoFTP failure -- Unable to view files on FTP server.", #MB_OK|#MB_ICONWARNING)
        EndIf
        CloseFile(10)
      Else
        MessageRequester("File Error", "AutoFTP Failure -- Cannot create server.dat file.", #MB_OK|#MB_ICONWARNING)
      EndIf
      If FileSize("C:\ONELOG\CUSTOMER.ARC") = -1
        ;Debug "CUSTOMER.ARC is missing", 2
        ForEach fileList()
          If fileList() = "CUSTOMER.ARC"
            present = #True
          EndIf
        Next
        If present = 0
          AddElement(fileList.s())
          fileList() = "CUSTOMER.ARC" ; download if file is missing locally no matter what.
        EndIf
      EndIf
      If usrprfs = 0
        SendFTPFile(0,HOME$+RegisteredUser$,RegisteredUser$)
      EndIf
      CloseFTP(0)
    Else
      ;Debug "NO Connect"
      fail + 1
      Delay(1400)
    EndIf
    ;Debug "inventory home "+Str(count)
  Until count = 3
  If count = 3
     MessageRequester("FTP Login failure", "FTP is enabled." + Chr(10) + "Cannot inventory ftp.domain.com") 
   Endif
   
So now I am abandoning the 3 time fail approach. Instead I grab the file timestamp before I try FTP and compare that after FTP. If different then success. Just can't rely on OpenFTP to return true when successful, at least in 64 Bit ver 5.40. And I don't see any difference in ver 5.62 or 6.21. It's a crying shame.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
infratec
Always Here
Always Here
Posts: 7712
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFtp() only fails -- other clients work fine.

Post by infratec »

You know that you have a space in front of the URL?
Randy Walker
Addict
Addict
Posts: 1171
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: OpenFtp() only fails -- other clients work fine.

Post by Randy Walker »

infratec wrote: Wed Dec 03, 2025 8:44 am You know that you have a space in front of the URL?
Yes I see that now and really Should not even have the ftp:// either. Works fine without. OpenFTP()) just does not report reliably.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Post Reply