FTPS (windows needs additional files)

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

FTPS (windows needs additional files)

Post 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.
Last edited by infratec on Sun Nov 13, 2022 4:06 pm, edited 6 times in total.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: FTPS (windows needs additional files)

Post by Little John »

Code: Select all

IncludeFile "libcurl.pbi"
And where can I get "libcurl.pbi"? :-)
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTPS (windows needs additional files)

Post 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
Last edited by infratec on Sun Nov 13, 2022 4:07 pm, edited 1 time in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post 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
ImageThe happiness is a road...
Not a destination
PeWa
New User
New User
Posts: 7
Joined: Fri Sep 06, 2019 8:25 pm

Re: FTPS (windows needs additional files)

Post 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
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTPS (windows needs additional files)

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post 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$)
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTPS (windows needs additional files)

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post by Kwai chang caine »

Thanks a lot INFRATEC i try and say to you :wink: 8)
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post 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
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTPS (windows needs additional files)

Post by infratec »

I extended libcurl.pbi

viewtopic.php?p=591235
Last edited by infratec on Sun Nov 13, 2022 4:08 pm, edited 3 times in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post 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")
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTPS (windows needs additional files)

Post by infratec »

My example is for download a file, not for upload.

Have you written a upload version?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: FTPS (windows needs additional files)

Post 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
ImageThe happiness is a road...
Not a destination
Post Reply