Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use cURL?
Message
From
29/08/2019 17:11:31
 
 
To
28/08/2019 18:29:26
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01670380
Message ID:
01670433
Views:
57
Thank you Rick.

>>Anyone can tell me how to use cUrl in VFP?
>>
>>Right now I am using TwilioX. There is libcurl class in there, so I guess that everything should be there to let me use services provided by enterprises providing cUrl access.
>>
>>I want to send emails by going through SendGrid. SendGrid will let me do it with cUrl.
>>
>>Anyone here that can provide me a way to use cUrl with VFP? Either by using the class that comes with TwilioX or by another way?
>
>I used the C-based libcurl and created a DLL that had a simple interface to VFP, and then let the code in the DLL handle the normal function calls.
>
>I have the code at work, which I cannot share, but I can take you through how to do it if you're interested. It's not particularly difficult. It just required a bit of trial and error to get it setup the first time.
>
>My API now features these functions:
>
**********
>* FTP.DLL handles FTP communication using a baked in copy of libcurl
>*****
>    * Set the progress callback bind id
>    DECLARE INTEGER ftp_callback_bind_id IN (this.cDllName) ;
>                                        INTEGER wmftp_progress_callback_custom_id
>                                        * This is a custom value at or above WM_USER (0x400)
>                                        * Note:  The default value is 0x3693
>
>    * No return value
>    DECLARE         ftp_url             IN (this.cDllName) ;
>                                        STRING  cUrl
>
>    * No return value
>    DECLARE         ftp_credentials     IN (this.cDllName) ;
>                                        STRING  cName, ;                    && User name
>                                        STRING  cPassword                   && Password
>
>    * Returns positive for byte written, negative for error codes
>    DECLARE INTEGER ftp_put             IN (this.cDllName) ;
>                                        STRING  cLocalPathname, ;           && The local pathname to send
>                                        STRING  cPutPathname, ;             && Where to put it on the remote server
>                                        STRING@ cResult, ;                  && Our return result text (if any)
>                                        INTEGER nResultLength, ;            && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    * Returns positive for bytes retrieved, negative for error codes
>    DECLARE INTEGER ftp_dir             IN (this.cDllName) ;
>                                        STRING  cRemotePath, ;              && The remote path to inquire
>                                        STRING@ cDirText, ;                 && Our directory text returned from the remote
>                                        INTEGER nDirTextLength, ;           && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    * Returns positive for bytes retrieved, negative for error codes
>    DECLARE INTEGER ftp_get             IN (this.cDllName) ;
>                                        STRING  cGetPathname, ;             && The remote pathname to retrieve
>                                        STRING  cLocalPathname, ;           && Where to put it on our local machine
>                                        STRING@ cResult, ;                  && Our return result text (if any)
>                                        INTEGER nResultLength, ;            && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    DECLARE INTEGER ftp_delete          IN (this.cDllName) ;
>                                        STRING  cDeletePathname, ;          && The remote pathname to retrieve
>                                        STRING@ cResult, ;                  && Our return result text (if any)
>                                        INTEGER nResultLength, ;            && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    DECLARE INTEGER ftp_rename          IN (this.cDllName) ;
>                                        STRING  cRenameOldFilename, ;       && Old remote pathname
>                                        STRING  cRenameNewFilename, ;       && New remote pathname
>                                        STRING@ cResult, ;                  && Our return result text (if any)
>                                        INTEGER nResultLength, ;            && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    DECLARE INTEGER ftp_md              IN (this.cDllName) ;
>                                        STRING  cNewDirectoryPathname, ;    && New directory to create
>                                        STRING  cResult, ;                  && Our return result text (if any)
>                                        INTEGER nResultLength, ;            && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    DECLARE INTEGER ftp_rd              IN (this.cDllName) ;
>                                        STRING  cRemoveDirectoryPathname, ; && Remote directory to remove
>                                        STRING  cResult, ;                  && Our return result text (if any)
>                                        INTEGER nResultLength, ;            && Length of the return result text storage area
>                                        INTEGER nHwndCallback               && See ftp_callback_bind_id()
>
>    * Note:  CURL errors are less than 64 characters or so (I use 200 to be safe)
>    DECLARE INTEGER ftp_errorinfo       IN (this.cDllName) ;
>                                        INTEGER nErrorNum, ;                && The error code
>                                        STRING@ cErrorText, ;               && Error text storage area
>                                        INTEGER nErrorTextLength            && Length of the error text storage area
>
>So in VFP, I issue simple commands, like:
>
ftp_url("ftps.path.to.whatever.com")
>ftp_credentials("login", "password")
>lcResult = SPACE(1024)
>lnResult = ftp_put("c:\temp\file.zip", "/file.zip", @lcResult, LEN(lcResult), 0)
>* Result is in LEFT(lcResult, lnResult)
*******************************************************
Save a tree, eat a beaver.
Denis Chassé
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform