Page 1 of 1

LibCurl to enumerate remote files and foders [Resolved]

Posted: Wed Aug 07, 2024 3:11 pm
by Kwai chang caine
Hello at all :D

I try to use this splendid wrapper than INFRATEC have create for we own 8)
Unfortunately i have not found how ask at CURL to enumerate the elements in the remote path of the server :oops:
I have searched all yesterday and just find #CURLOPT_FTPLISTONLY, LIST, and #CURLOPT_VERBOSE who perhaps can have a link with this that i need, but that not works, i just obtain a "OK" :|
If someone have understand something to the behaviour of this DLL nearly also complicated for me to understant than Scintilla :oops:

Code: Select all

#Username$ = "XXXX"
#Password$ = "XXXXX" 

InitNetwork()
#LibCurl_ExternalDLL = #True
IncludeFile "libcurl.pbi"

#REMOTE_URL = "sftp://MyFtpServer.fr/var/www/html/"

Define curl.i, res.i, *headerlist

curl_global_init(#CURL_GLOBAL_DEFAULT)
curl = curl_easy_init()

If curl
 
 *headerlist = curl_slist_append(*headerlist, "LIST ")    
 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_VERBOSE, 1);
 curl_easy_setopt(curl, #CURLOPT_FTPLISTONLY, 1)
 
 res = curl_easy_perform(curl)
 
 If res = #CURLE_OK
  Debug "Ok"
 Else
  Debug "Error: " + curl_easy_strerror(res)
 EndIf
 
 curl_slist_free_all(*headerlist)
 curl_easy_cleanup(curl)
 
EndIf

curl_global_cleanup()
Have a good day

Re: LibCurl to enumerate remote files and foders

Posted: Wed Aug 07, 2024 8:06 pm
by infratec
This returns the directory:

Code: Select all

; https://www.purebasic.fr/english/viewtopic.php?p=562174#p562174

; FTPS get dir

EnableExplicit

#LibCurl_ExternalDLL = #True
IncludeFile "libcurl.pbi"


#REMOTE_URL = "ftp://url/"
#Username$ = "xxx"
#Password$ = "yyy"

Define curl.i, res.i
Define UserData.libcurl_userdata_structure


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)
  
  curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @LibCurl_WriteFunction())
  curl_easy_setopt(curl, #CURLOPT_WRITEDATA, @UserData)
  
  curl_easy_setopt(curl, #CURLOPT_USE_SSL, #CURLUSESSL_ALL)
  curl_easy_setopt(curl, #CURLOPT_FTPSSLAUTH, #CURLFTPAUTH_TLS)
  
  ; accept insecure certificates
  curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False)
  curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False)
  
  curl_easy_setopt(curl, #CURLOPT_VERBOSE, #True)
  
  res = curl_easy_perform(curl)
  If res = #CURLE_OK
    Debug "Ok"
    Debug PeekS(UserData\Memory, MemorySize(UserData\Memory), #PB_UTF8|#PB_ByteLength)
  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()

Re: LibCurl to enumerate remote files and foders

Posted: Thu Aug 08, 2024 3:42 pm
by Kwai chang caine
One thousand of thanks MASTER 8)
It's exactely what i search to do since several day

And I take this opportunity for congratulate you for this merveillous job you have do for give acces to CURL with PB
Thanks to you, we can replace the old FTP library which is no longer of any use to us, since now all servers are encrypted whether we like it or not :|

I wish you a very very good day 8)