Page 1 of 2

LibCurl refresh list elements [Resolved]

Posted: Fri Aug 09, 2024 6:20 pm
by Kwai chang caine
Hello at all :D

Since several days i fighting with the LibCurl :oops:

Thanks to INFRATEC i can now :

1/ Read the list of elements of a folder => DirList()
2/ Put a file in the remote folder

But when i want refresh the list, i call a new time the DirList() procedure, and that not works :|
I have the return
LibCurl wrote:Error: Error in the SSH layer
There are surely a variable bad used, or not initialized, but i don't find where :oops:

If someone understand the problem, because i believe i coming crazy :twisted:

Code: Select all

#LibCurl_ExternalDLL = #True
IncludeFile "libcurl.pbi"
Global curl.i, res.i, Url$
Global UserData.libcurl_userdata_structure


#REMOTE_URL = "sftp://MyFtpServer.fr/var/www/html/"
#Username$ = "XXXX"
#Password$ = "XXXXX" 

InitNetwork()
curl_global_init(#CURL_GLOBAL_DEFAULT)
curl = curl_easy_init()
curl_easy_setopt_str(curl, #CURLOPT_USERNAME, #Username$)
curl_easy_setopt_str(curl, #CURLOPT_PASSWORD, #Password$)

Procedure DirList()
 
 curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL)
 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
 
 
EndProcedure

If curl
 
 DirList()
 #LOCAL_FILE = "C:\Windows\Win.ini"
 #REMOTE_FILE = "Win.ini"
 UserData\File = ReadFile(#PB_Any, #LOCAL_FILE)
 
 If UserData\File 
  
  *headerlist = curl_slist_append(*headerlist, "RNFR " + #REMOTE_FILE)
  
  curl_easy_setopt(curl, #CURLOPT_READFUNCTION, @LibCurl_ReadFunction())
  curl_easy_setopt(curl, #CURLOPT_READDATA, @UserData)
  curl_easy_setopt(curl, #CURLOPT_UPLOAD, 1)
  
  curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL + #REMOTE_FILE)
  curl_easy_setopt(curl, #CURLOPT_POSTQUOTE, *headerlist)
  
  ; optional
  curl_easy_setopt(curl, #CURLOPT_INFILESIZE, Lof(UserData\File))
  curl_easy_setopt(curl, #CURLOPT_USE_SSL, #CURLUSESSL_ALL)
  
  ; accept insecure certificates
  curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, #False)
  curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, #False)
  
  res = curl_easy_perform(curl)
  
  If res = #CURLE_OK
   Debug "Ok"
  Else
   Debug "Error: " + curl_easy_strerror(res)
  EndIf
  
  curl_slist_free_all(*headerlist)
  CloseFile(UserData\File)
  DirList()
  curl_easy_cleanup(curl)
  curl_global_cleanup()
  
 EndIf
 
EndIf
Have a good day

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 7:54 pm
by infratec
It is alway difficult to reuse a curl object.
This works:

Code: Select all

EnableExplicit

#LibCurl_ExternalDLL = #True
IncludeFile "libcurl.pbi"

Global curl.i, res.i, Url$
Global.libcurl_userdata_structure TxUserData, RxUserData

#REMOTE_URL = "sftp://MyFtpServer.fr/var/www/html/"
#Username$ = "XXXX"
#Password$ = "XXXXX" 

#LOCAL_FILE = "C:\tmp\Win.ini"
#REMOTE_FILE = "Win.ini"


Procedure DirList()
 
 curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL)
  
 res = curl_easy_perform(curl)
 If res = #CURLE_OK
  Debug "Ok"
  Debug PeekS(RxUserData\Memory, MemorySize(RxUserData\Memory), #PB_UTF8|#PB_ByteLength)
  FreeMemory(RxUserData\Memory)
  RxUserData\Memory = #Null
 Else
  Debug "Error: " + curl_easy_strerror(res)
 EndIf
 
EndProcedure




;InitNetwork()

curl_global_init(#CURL_GLOBAL_DEFAULT)

curl = curl_easy_init()
If curl
 
 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, @RxUserData)
 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)
 
 DirList()
 
 TxUserData\File = ReadFile(#PB_Any, #LOCAL_FILE)
 
 If TxUserData\File
  
  curl_easy_setopt(curl, #CURLOPT_READFUNCTION, @LibCurl_ReadFunction())
  curl_easy_setopt(curl, #CURLOPT_READDATA, @TxUserData)
  curl_easy_setopt(curl, #CURLOPT_UPLOAD, 1)
  
  curl_easy_setopt_str(curl, #CURLOPT_URL, #REMOTE_URL + #REMOTE_FILE)
  
  ; optional
  curl_easy_setopt(curl, #CURLOPT_INFILESIZE, Lof(TxUserData\File))
  
  res = curl_easy_perform(curl)
  If res = #CURLE_OK
   Debug "Ok"
  Else
   Debug "Error: " + curl_easy_strerror(res)
  EndIf
  
  curl_easy_setopt(curl, #CURLOPT_POSTQUOTE, #Null)
  curl_easy_setopt(curl, #CURLOPT_INFILESIZE, -1)
  curl_easy_setopt(curl, #CURLOPT_UPLOAD, 0)
  
  CloseFile(TxUserData\File)
  
  DirList()
  
 EndIf
 
 curl_easy_cleanup(curl)
 
EndIf

curl_global_cleanup()
The file is uploaded, but I get a QOUTE error.
Is there a QOUTE at the server?

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:07 pm
by Kwai chang caine
Hello INFRATEC 8)

Thanks a lot for your precious answer
Master wrote:It is alway difficult to reuse a curl object.
If it's you who say that, then never i haven a chance to find a solution :oops:
Master wrote:The file is uploaded, but I get a QOUTE error.
Yes me too, i have always this quote error, and already ask, if someone have a solution
https://www.purebasic.fr/english/viewto ... 00#p625500
Master wrote:Is there a QOUTE at the server?
I don't know what is "QOUTE" or "QUOTE" at a server :oops:

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:15 pm
by infratec
Sorry it is QUOTE.

Thats a return value of the ftp server.
21 FTP quote error. A quote command returned error from the server.
Try a 'normal' user with full read/write access.

A QUOTE is normally a space limit for the user.

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:31 pm
by Kwai chang caine
Master wrote:Try a 'normal' user with full read/write access.
I must send this command "Normal" and "Read/wrtite acces" in CURL or on my server ?
Because i have see this parameter in filezilla, but not in CURL :|

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:34 pm
by infratec
I fixed it. (listing above)

The RNFR command is not neccessary when you don't want to rename the file.
And if it is used, a RNTO is needed too.
A QUOTE command is a command which is executed on th ftp server.

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:40 pm
by infratec
Adjusted some misplaced commands.

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:48 pm
by Kwai chang caine
Waooouuuh !!!!!
You are too strong !!!
:shock:

But I guess I'm not telling you anything new. :mrgreen:

If I didn't hold back, I would almost want to kiss you, so much this story was starting to get on my nerves so much :|

I can go to bed now with the free spirit 8)
Finally a little bit like i am always ....what :mrgreen:

Have a good night magical MASTER of the NET 8)

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 8:50 pm
by infratec
Build in PB 6.11
--- LibCurl Info ---
Version: 7.68.0
Host: i386-pc-win32
SSL: Schannel

Protocols:
ftp
ftps
http
https
smtp
smtps
--- LibCurl Info ---
But not sftp :cry:
You are using sftp.

With ftps you can use the internal libcurl and don't need the external dll. (remove #LibCurl_ExternalDLL = #True)
Or try it with the original PB commands.

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 9:06 pm
by Kwai chang caine
Yes i use SFTP in filezilla because FTPS not exist :|
But the worst, if i believe SFTP is the same thing than FTPS :oops:

In fact i don't know what i must use...

Image

I just want to go to my server ...,

Like before all this bad secure protections come !!!!

Re: LibCurl refresh list elements

Posted: Fri Aug 09, 2024 9:12 pm
by infratec
Hey in the current beta 6.12b2 SFTP is added :!: :!: :!:

Re: LibCurl refresh list elements [Resolved]

Posted: Fri Aug 09, 2024 9:32 pm
by Kwai chang caine
Yes, i just see that today :shock:
But i'm affraid to change from v5.73 to the C Backend, without have numerous problems of compatibility in several of my codes :oops:

I search since a long time, but i not understand how use NATIVE curl in PB :oops:

Image

Damn, sometimes I'd better open a grocery store
and sell carrots, I'd surely be more efficient. :cry:

Re: LibCurl refresh list elements [Resolved]

Posted: Fri Aug 09, 2024 9:41 pm
by infratec
I'm still using the asm backend with PB 6.12 beta 2

But I had to extend my libcurl.pbi for PB 6.12 beta 2

So you need to download it again.

Re: LibCurl refresh list elements [Resolved]

Posted: Fri Aug 09, 2024 9:47 pm
by Kwai chang caine
I'm still using the asm backend with PB 6.12 beta 2
What !!! :shock:
It's possible to use the ASM backend after the 5.73 ???
You whant to say, you use just the IDE of the v6.12 with the old v5.73 ASM backend ? or i have again nothing understood and FRED continue to update the ASM backend in the v6 versions ????

Re: LibCurl refresh list elements [Resolved]

Posted: Sat Aug 10, 2024 8:19 am
by infratec
The default is still the asm backend.
If you want to use the C compiler you have to choose it by hand.

I think it is not further developed.
But my 20 year old car is still driving, so what?