[Done] OpenFTP not work on 6.21

Post bugreports for the Windows version here
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

[Done] OpenFTP not work on 6.21

Post by drgolf »

Hello,

On windows 10 PRO x64, this line with :

serveur.s : ftpperso.free.fr
user.s : myident
pw.s : mypassword
port.i :21

Code: Select all

If OpenFTP(0,serveur,user,pw,#True,port) 

With PB 6.11 : all work well and i can list the files.
On PB 6.21 x64 ASM or C BE : unable to connect !!

With this line :

Code: Select all

If OpenFTP(0,serveur,user,pw)


I have connection but garbage on listing !!

There is changes between versions... What can i do for my application ?

This is an app that work very well previously, without any glitch.

Any help appreciated.
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFTP not work on 6.21

Post by infratec »

Works for me:

PB 6.21 x64

Code: Select all

If OpenFTP(0, "xxx.xx", "yyyy", "zzz", #True, 21)
  Debug "Ok"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
EndIf
Last edited by infratec on Sun Jul 13, 2025 3:58 pm, edited 2 times in total.
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

Hello,

For me no connexion on ftp serveur FREE.fr with 6.21 : openftp return 0
Connexion with the same app and same param with pb 6.11 on x64 or x86

....
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFTP not work on 6.21

Post by infratec »

Works here too:

PureBasic 6.21 (Windows - x64)
ASM and C backend

Code: Select all

serveur.s = "ftp.free.fr"
user.s = "anonymous"
pw.s = ""
port.i = 21

If OpenFTP(0, serveur, user, pw, #True, port)
  Debug "Open"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
Else
  Debug "Not open"
EndIf
->
Open
tmp
stats
pub
nzb
mirrors
lost+found
awstats
MPlayer -> mirrors/mplayerhq.hu/MPlayer
Please test exact this code. What's your result?
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

@infratec with your code : same result, BUT with :

serveur.s = "ftpperso.free.fr"
user.s = "user"
pw.s = "pass"
port.i = 21

Code: Select all

If OpenFTP(0, serveur, user, pw, #True, port)
  Debug "Open"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
Else
  Debug "Not open"
EndIf
NOT Open.

With PB 6.11 : ftpperso >>> Open

Thanx for your help... Maybe with libcurl is it possible ?
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFTP not work on 6.21

Post by infratec »

Strange ...

Of course you can try my libcurl.pbi
Maybe you get an error if it fails, or you can see what fails.

viewtopic.php?t=80118

Use the FTPS_GetDirectory.pb as base.

You can remove all SSL stuff.
And comment out #LibCurl_ExternalDLL = #True

Btw.: PB uses libcurl for FTP.


Or try this:

Code: Select all

EnableExplicit

IncludeFile "libcurl.pbi"


;#REMOTE_URL$ = "ftp://ftp.free.fr/stats/"
;#REMOTE_URL$ = "ftp://ftp.free.fr/tmp/"
#REMOTE_URL$ = "ftp://ftp.free.fr/"
#Username$ = "anonymous"
#Password$ = ""

Structure FTPDirStructure
  Rights$
  HardLinks.i
  User$
  Group$
  Size.i
  Date$
  Name$
EndStructure



Define curl.i, res.i, Entries$, i.i, Line$
Define UserData.libcurl_userdata_structure

NewList DirList.FTPDirStructure()

CompilerIf #PB_Compiler_Version < 600
  InitNetwork()
CompilerEndIf



curl_global_init(#CURL_GLOBAL_DEFAULT)

curl = curl_easy_init()
If curl
  
  curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL$)
  
  curl_easy_setopt_str(curl, #CURLOPT_USERNAME, #Username$)
  curl_easy_setopt_str(curl, #CURLOPT_PASSWORD, #Password$)
  
  curl_easy_setopt(curl, #CURLOPT_FTP_USE_EPSV, 0)	; PASV
  
  curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @LibCurl_WriteFunction())
  curl_easy_setopt(curl, #CURLOPT_WRITEDATA, @UserData)
  
  curl_easy_setopt(curl, #CURLOPT_VERBOSE, #True)
  
  res = curl_easy_perform(curl)
  If res = #CURLE_OK
    If UserData\Memory
      ;ShowMemoryViewer(UserData\Memory, MemorySize(UserData\Memory))
      Entries$ = PeekS(UserData\Memory, MemorySize(UserData\Memory), #PB_UTF8|#PB_ByteLength)
      ;Debug Entries$
      i = 1
      Line$ = StringField(Entries$, i, #CRLF$)
      While Line$ <> ""
        AddElement(DirList())
        DirList()\Rights$ = Left(Line$, 10)
        Line$ = Mid(Line$, 11)
        DirList()\HardLinks = Val(LTrim(Line$))
        Line$ = Mid(Line$, 7)
        DirList()\User$ = RTrim(Left(Line$, 9))
        Line$ = Mid(Line$, 10)
        DirList()\Group$ = RTrim(Left(Line$, 9))
        Line$ = Mid(Line$, 11)
        DirList()\Size = Val(LTrim(Line$))
        Line$ = Mid(Line$, 9)
        DirList()\Date$ = Left(Line$, 12)
        DirList()\Name$ = Mid(Line$, 14)
        i + 1
        Line$ = StringField(Entries$, i, #CRLF$)
      Wend
      FreeMemory(UserData\Memory)
      UserData\Memory = #Null
    EndIf
    
  Else
    Debug "Error: " + curl_easy_strerror(res)
  EndIf
  
  curl_easy_cleanup(curl)
  
Else
  MessageRequester("Error", "Was not able to init curl")
EndIf

curl_global_cleanup()


ForEach DirList()
  Select Left(DirList()\Rights$, 1)
    Case "-"
      Debug "File: " + DirList()\Rights$ + " " + Str(DirList()\HardLinks) + " " + DirList()\User$ + " " + DirList()\Group$ + " " + Str(DirList()\Size) + " " + DirList()\Date$ + " " + DirList()\Name$
    Case "d"
      Debug "Dir : " + DirList()\Rights$ + " " + Str(DirList()\HardLinks) + " " + DirList()\User$ + " " + DirList()\Group$ + " " + Str(DirList()\Size) + " " + DirList()\Date$ + " " + DirList()\Name$
    Case "l"
      Debug "Link: " + DirList()\Rights$ + " " + Str(DirList()\HardLinks) + " " + DirList()\User$ + " " + DirList()\Group$ + " " + Str(DirList()\Size) + " " + DirList()\Date$ + " " + DirList()\Name$  
  EndSelect
Next
If you want to specify a port, you have to add it to the url:

Code: Select all

#REMOTE_URL = "ftp://ftp.free.fr:21/"
Last edited by infratec on Sun Jul 13, 2025 5:53 pm, edited 1 time in total.
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

@infratec : all work fine with libcurl.... babababa... Its not easy to implement in my app... and very big dll...

I use libcurl for mail client... but for ftp client...

Thanx for your help.

In the libcurl zip the examples ftps_dir and ftps_getdirectory are the same files.
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFTP not work on 6.21

Post by infratec »

You don't need the external dll.

the used libcurl stuff is inbuild.
As I told you PB uses libcurl too.

An yes, I just removed FTPS_dir.pb

I added the example above as FTP_dir.pb
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

@infratec,

There is a change in PB with FTP lib after version 6.11
My application work with PB11 but not with versions after.

So, i work on libcurl FTP... I can have the dir list.
How to create/delete dir with libcurl ?

Thanx by advance...
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFTP not work on 6.21

Post by infratec »

I added 2 examples to the libcurl zip file.
You can only remove empty directories.
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

Hi Infratec,

Thanx for examples using libcurl for rmdir and creaye dir...

Not easy to change my app with libcurl... big work...

My problem is for delete recursive dir not empty...
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: OpenFTP not work on 6.21

Post by Fred »

With 6.30b2, you will be able to use a new debug flag to spot the issue:

Code: Select all

serveur.s = "ftp.free.fr"
user.s = "anonymous"
pw.s = ""
port.i = 21

If OpenFTP(0, serveur, user, pw, #PB_FTP_Passive | #PB_FTP_Debug, port)
  Debug "Open"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
Else
  Debug "Not open"
EndIf
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

Hello Fred,

I have tested the new flag #pb_ftp_debug, like this :

Code: Select all

serveur.s = "ftpperso.free.fr"
user.s = "mylogin"
pw.s = "mypassword"
port.i = 21

If OpenFTP(0, serveur, user, pw, #PB_FTP_Passive | #PB_FTP_Debug, port)
  Debug "Open"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
Else
  Debug "Not open"
EndIf

And the debug window show "Not open"

I use libcurl now for my ftp client and it work with the same ident (with the inbuilt pb-libcurl : dont use libcurl external dll).

Strangely, with the example you gave :

Code: Select all

serveur.s = "ftp.free.fr"
user.s = "anonymous"
pw.s = ""
port.i = 21

If OpenFTP(0, serveur, user, pw, #PB_FTP_Passive | #PB_FTP_Debug, port)
  Debug "Open"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
Else
  Debug "Not open"
EndIf
The debug give :
Open
tmp
stats
pub
nzb
mirrors
lost+found
awstats
MPlayer -> mirrors/mplayerhq.hu/MPlayer
For Free FTP, the PB libcurl works since version 6.11. After, not...
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenFTP not work on 6.21

Post by infratec »

You need this:

Code: Select all

serveur.s = "ftp.free.fr"
user.s = "anonymous"
pw.s = ""
port.i = 21

OpenConsole()

If OpenFTP(0, serveur, user, pw, #PB_FTP_Passive | #PB_FTP_Debug, port)
  Debug "Open"
  
  If ExamineFTPDirectory(0)
    While NextFTPDirectoryEntry(0)
      Debug FTPDirectoryEntryName(0)
    Wend
    FinishFTPDirectory(0)
  EndIf
  
  CloseFTP(0)
Else
  Debug "Not open"
EndIf

Input()

CloseConsole()
And set the executable format to 'console' in compiler options.
Then copy (right click, select all, press return) the output in the console window and paste it here.
drgolf
Enthusiast
Enthusiast
Posts: 114
Joined: Tue Mar 03, 2009 3:40 pm
Location: france

Re: OpenFTP not work on 6.21

Post by drgolf »

Hello Infratec,

As i always said, with anonymous and no pw : work ok.

But with : ftpperso.free.fr, ident and pw, i have on debug Not open, and in console :

* timeout on name lookup is not supported
* Trying 212.27.63.3:21...
* TCP_NODELAY set
* Connected to ftpperso.free.fr (212.27.63.3) port 21 (#0)
* Server auth using Basic with user 'xxxxx'
> HEAD / HTTP/1.1
Host: ftpperso.free.fr:21
Authorization: Basic bWVtZG9jOno4aWp2eTl1
Accept: */*

* Received HTTP/0.9 when not allowed

* Closing connection 0

Post Reply