Page 1 of 2

FTPS (windows needs additional files)

Posted: Sun Nov 22, 2020 7:31 pm
by infratec
Hi,

for this example you need for windows:

libcurl.dll
libcrypto-1_1.dll
libssl-1_1.dll

From:
https://curl.haxx.se/windows/

curl for XX bit

and below
OpenSSL

Or simply use my zip file:
viewtopic.php?p=591235

for linux:
nothing todo, since the full libcurl.so is installed and PB uses this 'full' lib.

for OSX:
no idea, but I think it behaves like linux.

Code: Select all

; FTPS
; 
; https://curl.se/libcurl/c/ftpsget.html
; 

EnableExplicit

#LibCurl_DLL$ = "libcurl.dll"

IncludeFile "libcurl.pbi"


Structure FtpFileStructure
  filename$
  file.i
EndStructure


ProcedureC.l my_fwrite(*buffer, Size, NMemB, *out.FtpFileStructure)
  
  Protected Result.i
  
  
  If Not *out\file
    *out\file = CreateFile(#PB_Any, *out\filename$)
    If Not *out\file
      Result = -1
    EndIf
  EndIf
  
  If Result = 0
    Result = WriteData(*out\file, *buffer, (Size & 255) * NMemB)
  EndIf
  
  ProcedureReturn Result
  
EndProcedure



Define curl.i, ftpfile.FtpFileStructure, res.i


InitNetwork()

curl_global_init(#CURL_GLOBAL_DEFAULT)

curl = curl_easy_init()
If curl
  
  ftpfile\filename$ = GetPathPart(ProgramFilename()) + "file.txt"
  
  curl_easy_setopt_str(curl, #CURLOPT_URL, "ftps://user@server/home/user/file.txt")
  
  curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @my_fwrite())
  curl_easy_setopt(curl, #CURLOPT_WRITEDATA, @ftpfile)
  
  curl_easy_setopt(curl, #CURLOPT_USE_SSL, #CURLUSESSL_ALL)
  
  res = curl_easy_perform(curl)
  If res = #CURLE_OK
    Debug "Ok"
  Else
    Debug "Error: " + curl_easy_strerror(res)
  EndIf
  
  If IsFile(ftpfile\file)
    CloseFile(ftpfile\file)
  EndIf
  
  curl_easy_cleanup(curl)
  
EndIf

curl_global_cleanup()
Unfortunately I can not test it :mrgreen:
I have no FTPS server which I can access at the moment.
But it should work. If not: report it.

Re: FTPS (windows needs additional files)

Posted: Sun Nov 22, 2020 8:33 pm
by Little John

Code: Select all

IncludeFile "libcurl.pbi"
And where can I get "libcurl.pbi"? :-)

Re: FTPS (windows needs additional files)

Posted: Sun Nov 22, 2020 9:25 pm
by infratec
Ups..

I thought that everyone which has something todo with internet things has it already.

Here a link to a topic with a downloadlink:

viewtopic.php?p=591235

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 3:41 pm
by Kwai chang caine
Thanks a lot for this very useful code for me waiting a native FTPS PB function 8)

For connecting to my 1&1 IONOS FTPS space, i have the host

Code: Select all

accessXXXXXXX.webspace-data.io
I have the username

Code: Select all

uXXXXXXXXX
And i have the password

Code: Select all

Password
So i enter in curl_easy_setopt_str()

Code: Select all

curl_easy_setopt_str(curl, #CURLOPT_URL, "ftps://uXXXXXXXXX:Password@accessXXXXXXX.webspace-data.io/Domain.fr/My/Path/file.txt")
And i have this answer :|
PB wrote:Error: Unsupported protocol

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 4:12 pm
by PeWa
Kwai chang caine wrote:Thanks a lot for this very useful code for me waiting a native FTPS PB function 8)

For connecting to my 1&1 IONOS FTPS space, i have the host

Code: Select all

accessXXXXXXX.webspace-data.io
I have the username

Code: Select all

uXXXXXXXXX
And i have the password

Code: Select all

Password
So i enter in curl_easy_setopt_str()

Code: Select all

curl_easy_setopt_str(curl, #CURLOPT_URL, "ftps://uXXXXXXXXX:Password@accessXXXXXXX.webspace-data.io/Domain.fr/My/Path/file.txt")
And i have this answer :|
PB wrote:Error: Unsupported protocol

Another way for FTPS is RSBasics FTP.EX :
viewtopic.php?f=27&t=70380&hilit=ftps

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 4:22 pm
by infratec
@KCC

have you downloaded the needed dlls?
have you uncomment #LibCurl_DLL$ = "libcurl.dll" in the libcurl.pbi file?

Else only the internal libcurl lib is used which can only handle http and smtp.

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 4:35 pm
by Kwai chang caine
PeWa wrote:Another way for FTPS is RSBasics FTP.EX :
Thanks PeWa for your link :wink:
It's right RsBasic made a great works with his library 8)
But I do not like too much use owner librarys :oops:
Sometime she is not updating and if my software use it, it can't be updated too, because source are not availlable :|
It's not the first time that it happens ...
I just use big library, when i'm forced, because numerous programmers are behind, and if one stoppe, the others continue :)
But for the moment, it's not often i must use external or owner library, PB are so strong :shock:
It's the first time i can't do something of banal (Put a file on my server provider IONOS :shock: ) with PB 8)
MasterNet wrote:have you uncomment #LibCurl_DLL$ = "libcurl.dll" in the libcurl.pbi file?
Shit...i have forgetting :oops:

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 5:35 pm
by Kwai chang caine
I go in libcurl.pbi and there are not

Code: Select all

#LibCurl_DLL$ = "libcurl.dll"
worst there are not :shock:

Code: Select all

#LibCurl_DLL$
:|

The only one place where there are #LibCurl_DLL$ in "libcurl.pbi", it's here :wink:

Code: Select all

 LibCurl = OpenLibrary(#PB_Any, GetPathPart(ProgramFilename()) + #LibCurl_DLL$)

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 8:39 pm
by infratec
Sorry, but I have many variations off libcurl.pbi

I modified the listing above.

To be more 'free' I decided to set the constant outside of libcurl.pbi.

Download my libcurl zip file (link added above) and use the modified listing.
It should work.

Re: FTPS (windows needs additional files)

Posted: Tue Nov 24, 2020 8:43 pm
by Kwai chang caine
Thanks a lot INFRATEC i try and say to you :wink: 8)

Re: FTPS (windows needs additional files)

Posted: Wed Nov 25, 2020 2:47 pm
by Kwai chang caine
I have surely do a bullshit somewhere, this time your code say "curl_global_init()" is not a function :|
http://reec.fr/provisoire/FTPS.zip

Re: FTPS (windows needs additional files)

Posted: Wed Nov 25, 2020 6:00 pm
by infratec
I extended libcurl.pbi

viewtopic.php?p=591235

Re: FTPS (windows needs additional files)

Posted: Wed Nov 25, 2020 7:05 pm
by Kwai chang caine
Thanks a lot INFRATEC 8)
This time i have
Error: Timeout was reached
I think it's surely a wrong call of my FTPS server :oops:

If for connecting to my 1&1 IONOS FTPS space, i have the host
accessXXXXXXX.webspace-data.io
If my username is
uXXXXXXXXX
And my password
Password
And i want put the file in this path
/Domain.fr/My/Path/
Can you confirm the good call ?

Code: Select all

curl_easy_setopt_str(curl, #CURLOPT_URL, "ftps://uXXXXXXXXX:Password@accessXXXXXXX.webspace-data.io/Domain.fr/My/Path/file.txt")

Re: FTPS (windows needs additional files)

Posted: Wed Nov 25, 2020 8:14 pm
by infratec
My example is for download a file, not for upload.

Have you written a upload version?

Re: FTPS (windows needs additional files)

Posted: Wed Nov 25, 2020 8:35 pm
by Kwai chang caine
Aaaah !!! excuse me i have not understand that :oops:

In fact i need mainly a upload files
In my project i use only TXT files, so for "upload" txt file i make just a GET request
And for upload screenshot, i use your splendid code PHP 8)
What I miss, it's a FTPS for upload the PHP itself on the server :wink: create folder, put file etc .... for configuring automaticaly the SERVER and can run after my remote program :D