VFPConnection Library Update
It hasn’t been too many days since I posted an update to this library. The two big enhancements in that update was SSL support and a mechanism for tracing. It was fairly well received and appeared to work well for those that downloaded it, but I mentioned at the end of that blog entry that I wanted to do a few other enhancements surrounding FTP commands and HTTP Posts. This update provides that functionality among other things.


What’s New
I’ve added 10 new functions to the FLL and documentation. These include:



  • HTTPSimplePost

  • HTTPPost

  • FTPCommands

  • FTPSCommands

  • URLEncode

  • URLDecode

  • DateStrToEpochSec

  • SetConnectTimeout

  • SetResponseTimeout

  • CurlVersion

I’ve also done some refactoring within the library and a few performance enhancements (though it was pretty darn fast to already).


What’s Next
If you download and use this library then you might consider taking the time to provide me feedback and any suggestions you may have for further improving it. The update provided here is a testament to the fact that your feedback is valuable and an integral part of the improvement process for the stuff I provide to the VFP Community.


Until next time… Visual FoxPro Rocks!


VFPConnection FLL Download (400 KB approx.)


VFPConnection.FLL Sample Use Code:


*!* The code below is not designed to run all at once
*!* Run the individual examples seperately

********************************************************************
*!* Upload Examples
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
*!* FILE
?FILEGet(“File:///C:\Source.txt”, “C:\Destination.txt”, “MyProgress()”, “MyTrace()”)
*!* FTP
?FTPGet(“FTP://UserName:Password@somedomain.com/directory/Source.zip”, “C:\Destination.zip”, “MyProgress()”, “MyTrace()”)
*!* FTPS
?FTPSGet(“FTPS://UserName:Password@somedomain.com:21/directory/Source.zip”, “C:\Destination.zip”, “MyProgress()”, “MyTrace()”)
*!* HTTP
?HTTPGet(“http://www.somedomain.com/Source.htm”, “C:\Destination.htm”, “MyProgress()”, “MyTrace()”)
*!* HTTPS
?HTTPSGet(“https://www.somedomain.com/Source.htm”, “C:\Destination.htm”, “MyProgress()”, “MyTrace()”)
SET LIBRARY TO

********************************************************************
*!* Download Examples
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
*!* FILE
?FILEPut(“C:\Source.txt”, “File:///C:\Destination.txt”, “MyProgress()”, “MyTrace()”)
*!* FTP
?FTPPut(“C:\Source.zip”, “FTP://UserName:Password@somedomain.com/directory/Destination.zip”, “MyProgress()”, “MyTrace()”)
*!* FTPS
?FTPSPut(“C:\Source.zip”, “FTPS://UserName:Password@somedomain.com:21/directory/Destination.zip”, “MyProgress()”, “MyTrace()”)
*!* HTTP
?HTTPPut(“C:\Source.htm”, “http://www.somedomain.com/Destination.htm”, “MyProgress()”, “MyTrace()”)
*!* HTTPS
?HTTPSPut(“C:\Source.htm”, “https://www.somedomain.com/Destination.htm”, “MyProgress()”, “MyTrace()”)
SET LIBRARY TO

********************************************************************
*!* To String Examples
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
*!* FILE
?FILEToStr(“C:\Source.txt”)
*!* FTP
?FTPTOSTR(“FTP://UserName:Password@somedomain.com:21/directory/Source.txt”)
*!* FTPS
?FTPSTOSTR(“FTPS://UserName:Password@somedomain.com:21/directory/Source.txt”)
*!* HTTP
?HTTPToStr(“http://www.somedomain.com/Source.txt”)
*!* HTTPS
?HTTPSToStr(“https://www.somedomain.com/Source.txt”)
SET LIBRARY TO

********************************************************************
*!* HTTP Post Examples
********************************************************************
*!* Simple HTTP Post
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
LOCAL lcPost
m.lcPost = “fname=John&lname=Smith”
?HttpSimplePost(“http://www.snee.com/xml/crud/posttest.cgi”, m.lcPost, “”, “MyTrace()”)
SET LIBRARY TO

*!* MultiPart/Form-Data HTTP Post
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
LOCAL ARRAY aryPost(2,2)
aryPost(1,1) = “fname” && name
aryPost(1,2) = “test first” && value
aryPost(2,1) = “lname” && name
aryPost(2,2) = “test last” && value
?HttpPost(“http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi”, @aryPost, “”, “MyTrace()”)
SET LIBRARY TO

********************************************************************
*!* FTP Commands Example
********************************************************************
*!* Rename FTP Directory
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
LOCAL ARRAY aryFTPCommands(4)
aryFTPCommands(1) = “CWD /”
aryFTPCommands(2) = “PWD”
aryFTPCommands(3) = “RNFR MyDir”
aryFTPCommands(4) = “RNTO RenamedMyDir”
?FTPCommands(“FTP://username:password@somedomain.com/”, @aryFTPCommands, “MyTrace()”)
*!* ?FTPSCommands(“FTPS://username:password@somedomain.com/”, @aryFTPCommands, “MyTrace()”)
SET LIBRARY TO

********************************************************************
*!* URL Encode/Decode Example
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
LOCAL lcString, lcEncoded, lcDecoded
m.lcString = “A!B@C#D$E%F^G&H*I(J)K_L-M=N+O[P]Q{R}S|T\U:V;W’X,Y.Z<0>1/2?3©4©5©6©7©8©9″
m.lcEncoded = UrlEncode(m.lcString)
m.lcDecoded = UrlDecode(m.lcEncoded)
?“Escaped: “ + m.lcEncoded
?“Unescaped: “ + m.lcDecoded
?“Original : “ + m.lcString
SET LIBRARY TO

********************************************************************
*!* Setting Timeouts Example
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
SetConnectTimeout(30) && Default is 10 seconds
SetResponseTimeout(30) && Default is 10 seconds
SET LIBRARY TO

********************************************************************
*!* Datetime String to the number of seconds from Epoch (12 Midnight on January 1, 1970)
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
?DateStrToEpochSec(“Sun, 06 Nov 1994 08:49:37 GMT”)
?DateStrToEpochSec(“Sunday, 06-Nov-94 08:49:37 GMT”)
?DateStrToEpochSec(“Sun Nov 6 08:49:37 1994”)
?DateStrToEpochSec(“06 Nov 1994 08:49:37 GMT”)
?DateStrToEpochSec(“06-Nov-94 08:49:37 GMT”)
?DateStrToEpochSec(“Nov 6 08:49:37 1994”)
?DateStrToEpochSec(“06 Nov 1994 08:49:37”)
?DateStrToEpochSec(“06-Nov-94 08:49:37”)
?DateStrToEpochSec(“1994 Nov 6 08:49:37”)
?DateStrToEpochSec(“GMT 08:49:37 06-Nov-94 Sunday”)
?DateStrToEpochSec(“94 6 Nov 08:49:37”)
?DateStrToEpochSec(“1994 Nov 6”)
?DateStrToEpochSec(“06-Nov-94”)
?DateStrToEpochSec(“Sun Nov 6 94”)
?DateStrToEpochSec(“1994.Nov.6”)
?DateStrToEpochSec(“Sun/Nov/6/94/GMT”)
?DateStrToEpochSec(“Sun, 06 Nov 1994 08:49:37 CET”)
?DateStrToEpochSec(“06 Nov 1994 08:49:37 EST”)
?DateStrToEpochSec(“Sun, 12 Sep 2004 15:05:58 -0700”)
?DateStrToEpochSec(“Sat, 11 Sep 2004 21:32:11 +0200”)
?DateStrToEpochSec(“20040912 15:05:58 -0700”)
?DateStrToEpochSec(“20040911 +0200”)
SET LIBRARY TO

********************************************************************
*!* Determine the version of libcurl and OpenSSL that were used for VFPConnection.fll
********************************************************************
SET LIBRARY TO (LOCFILE(“vfpconnection.fll”,“FLL”))
?CURLVERSION()
SET LIBRARY TO

***********************
FUNCTION MyProgress() && Callback from the FLL can be used to track operation progress
***********************
*!* You can create your own function, procedure or method to handle this and name it whatever you want.
*!* The nConnectTotalBytes and nConnectBytesSoFar are private variables created on-the-fly by the FLL
?m.nConnectTotalBytes
?m.nConnectBytesSoFar
ENDFUNC

***********************
FUNCTION MyTrace() && Callback from the FLL used to provide a detailed trace of the operation
***********************
*!* You can create your own function, procedure or method to handle this and name it whatever you want.
*!* The nTraceDataType and cTraceData are private variables created on-the-fly by the FLL
#DEFINE TYPE_TEXT 0
#DEFINE TYPE_HEADER_IN 1
#DEFINE TYPE_HEADER_OUT 2
#DEFINE TYPE_DATA_IN 3
#DEFINE TYPE_DATA_OUT 4
#DEFINE TYPE_SSL_DATA_IN 5
#DEFINE TYPE_SSL_DATA_OUT 6
#DEFINE TYPE_END 7
?ICASE(m.nTraceDataType = TYPE_TEXT, “STATUS:”, ;
m.nTraceDataType = TYPE_HEADER_IN, , ;
m.nTraceDataType = TYPE_HEADER_OUT, “>SEND HEADER: “, ;
m.nTraceDataType = TYPE_DATA_IN, , ;
m.nTraceDataType = TYPE_DATA_OUT, “>SEND DATA: “, ;
m.nTraceDataType = TYPE_SSL_DATA_IN, , ;
m.nTraceDataType = TYPE_SSL_DATA_OUT, “>SEND SSL DATA: “, ;
m.nTraceDataType = TYPE_END, “END: “, “UNKNOWN: “)
??m.cTraceData
ENDFUNC



VFPConnection.FLL Documenation:





Function FTPGet()


Signature: FTPGet(cSourceURL, cDestination[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to download.


cDestination – The full path and file name where you want the source file saved.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to download a file from an FTP site.


In order to specify port or login information you would simply include them in cSourceURL, such as “FTP://myusername:mypassword@myftpsite.com:21/mydir/myfile.zip”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FTPSGet()


Signature: FTPSGet(cSourceURL, cDestination[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to download.


cDestination – The full path and file name where you want the source file saved.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to download a file from an FTP site that provides FTP over Secure Sockets Layer (SSL). It should be noted that this function does not check the site’s certificate for authenticity/validness nor does it compare the site to the identity specified by the certificate.


In order to specify port or login information you would simply include them in cSourceURL, such as “FTPS://myusername:mypassword@myftpsite.com:21/mydir/myfile.zip”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPGet()


Signature: HTTPGet(cSourceURL, cDestination[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to download.


cDestination – The full path and file name where you want the source file saved.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to download a file from a website.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPSGet()


Signature: HTTPSGet(cSourceURL, cDestination[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to download.


cDestination – The full path and file name where you want the source file saved.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to download a file from a a website that provides HTTP over Secure Sockets Layer (SSL). It should be noted that this function does not check the site’s certificate for authenticity/validness nor does it compare the site to the identity specified by the certificate.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FILEGet()


Signature: FILEGet(cSourceURL, cDestination[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The full path and file name to the file you wish to copy.


cDestination – The full path and file name where you want the source file saved.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to copy a file from a local or remote location.


The format for the cSourceURL parameter is slightly different than you might expect. In order to copy file C:\MyDir\MyFile.zip you would specify cSourceURL as “FILE:// C:\MyDir\MyFile.zip”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FTPPut()


Signature: FTPPut(cSource, cDestinationURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSource – The full path and file name of the file you want uploaded.


cDestinationURL – The URL to where the file specified in cSource should be uploaded to.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to upload a file to an FTP site.


In order to specify port or login information you would simply include them in cDestinationURL, such as “FTP://myusername:mypassword@myftpsite.com:21/mydir/myfile.zip”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FTPSPut()


Signature: FTPSPut(cSource, cDestinationURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSource – The full path and file name of the file you want uploaded.


cDestinationURL – The URL to where the file specified in cSource should be uploaded to.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to upload a file to an FTP site that provides FTP over Secure Sockets Layer (SSL). It should be noted that this function does not check the site’s certificate for authenticity/validness nor does it compare the site to the identity specified by the certificate.


In order to specify port or login information you would simply include them in cDestinationURL, such as “FTPS://myusername:mypassword@myftpsite.com:21/mydir/myfile.zip”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPPut()


Signature: HTTPPut(cSource, cDestinationURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSource – The full path and file name of the file you want uploaded.


cDestinationURL – The URL to where the file specified in cSource should be uploaded to.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to upload a file to a website.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPSPut()


Signature: HTTPSPut(cSource, cDestinationURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSource – The full path and file name of the file you want uploaded.


cDestinationURL – The URL to where the file specified in cSource should be uploaded to.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to upload a file to a website that provides HTTP over Secure Sockets Layer (SSL). It should be noted that this function does not check the site’s certificate for authenticity/validness nor does it compare the site to the identity specified by the certificate.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FILEPut()


Signature: FILEPut(cSource, cDestinationURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSource – The full path and file name of the file you want copied.


cDestinationURL – The full path and file name where the file specified in cSource should be copied to.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to copy a file to a local or remote location.


The format for the cDestinationURL parameter is slightly different than you might expect. In order to copy file C:\MyDir\MyFile.zip you would specify cDestinationURL as “FILE:// C:\MyDir\MyFile.zip”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FTPToStr()


Signature: FTPToStr(cSourceURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to return a string from.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Character Data – the contents of the file specified by cSourceURL


Remarks:


This function provides the ability to retrieve a file from an FTP site as a string.


In order to specify port or login information you would simply include them in cSourceURL, such as “FTP://myusername:mypassword@myftpsite.com:21/mydir/myfile.txt”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function FTPSToStr()


Signature: FTPSToStr(cSourceURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to return a string from.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Character Data – the contents of the file specified by cSourceURL


Remarks:


This function provides the ability to retrieve a file as a string from an FTP site that provides FTP over Secure Sockets Layer (SSL). It should be noted that this function does not check the site’s certificate for authenticity/validness nor does it compare the site to the identity specified by the certificate.


In order to specify port or login information you would simply include them in cSourceURL, such as “FTPS://myusername:mypassword@myftpsite.com:21/mydir/myfile.txt”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPToStr()


Signature: HTTPToStr(cSourceURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to download.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to retrieve a file from a website as a string.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPSToStr()


Signature: HTTPSToStr(cSourceURL[, cProgressCallback[, cTraceCallback]])


Parameters:


cSourceURL – The URL to the file you wish to download.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


This function provides the ability to retrieve a file as a string from a website that provides HTTP over Secure Sockets Layer (SSL). It should be noted that this function does not check the site’s certificate for authenticity/validness nor does it compare the site to the identity specified by the certificate.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPSimplePost()


Signature: HTTPSimplePost(cPostURL, cPostData[, cProgressCallback[, cTraceCallback]])


Parameters:


cPostURL – The URL to which you want to post.


cPostData – A string consisting of a series of key-value pairs.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


The key-value pairs sent to cPostData are in the form of key1=value1. Additional key-value pairs must be delimited by “&”, such as “firstname=John&lastname=Smith”.


When the cProgressCallback is called 2 variables (nConnectTotalBytes and nConnectBytesSoFar) are created dynamically by the FLL. These variables can be used within the specified function, procedure, or method to determine the total size of the source file in bytes as well as the total progress of the operation (Percentage = 100 * nConnectBytesSoFar / nConnectTotalBytes).


When the cTraCallback is called 2 variables (nTraceDataType and cTraceData) are created dynamically by the FLL. The variable nTraceDataType specifies the type of operation that produced the information contained in cTraceData. The possible values for nTraceDataType are as follows: 0 = Text, 1 = Header In, 2 = Header Out, 3 = Data In, 4 = Data Out, 5 = SSL Data In, 6 = SSL Data Out, 7 = End.






Function HTTPPost()


Signature: HTTPPost(cPostURL, aPostData[, cProgressCallback[, cTraceCallback]])


Parameters:


cPostURL – The URL to the file you wish to download.


aPostData – A multi-dimensional array containing key-value pairs


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


The aPostData array must be sent in by reference. The key-value pairs in aPostData must have the keys in column 1 and the values in column 2, such as:


aPostData(1,1) = “firstname”
aPostData(1,2) = “John”
aPostData(2,1) = “lastname”
aPostData(2,2) = “Smith”






Function FTPCommands()


Signature: FTPCommands(cFTPURL, aCommands[, cProgressCallback[, cTraceCallback]])


Parameters:


cFTPURL – The URL to the FTP site you wish to interact with.


aCommands – A single dimension array containing the commands you wish to have run on the FTP site.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


In order to specify port or login information you would simply include them in cFTPURL, such as “FTP://myusername:mypassword@myftpsite.com:21/.

The aCommands array must be sent in by reference. The aCommands is an array of FTP commands (as defined by RFC 959), such as:

aCommands(1) = “CWD /”
aCommands(2) = “PWD”
aCommands(3) = “RNFR MyDir”
aCommands(4) = “RNTO RenamedMyDir”






Function FTPSCommands()


Signature: FTPSCommands(cFTPSURL, aCommands[, cProgressCallback[, cTraceCallback]])


Parameters:


cFTPSURL – The URL to the FTP site you wish to interact with.


aCommands – A single dimension array containing the commands you wish to have run on the FTP site.


cProgressCallback – An optional string denoting a function, procedure, or method that you want fired whenever a read/write occurs, such as “MyProgress()”.


cTraceCallback – An optional string denoting a function, procedure, or method that you want fired whenever additional information regarding the status of the operation is available. Eample: “MyTrace()”


Return Value:


Logical – returns .T. if successful or .F. if the operation has failed.


Remarks:


In order to specify port or login information you would simply include them in cFTPSURL, such as “FTPS://myusername:mypassword@myftpsite.com:21/.

The aCommands array must be sent in by reference. The aCommands is an array of FTP commands (as defined by RFC 959), such as:

aCommands(1) = “CWD /”
aCommands(2) = “PWD”
aCommands(3) = “RNFR MyDir”
aCommands(4) = “RNTO RenamedMyDir”






Function URLEncode()


Signature: URLEncode(cString)


Parameters:


cString – The string you want encoded (escaped).


Return Value:


Character – returns the encoded equivalent of cString.


Remarks:


This function provides libcurl’s “URL Escape” functionality. Any character in cString that is not a-z, A-Z, or 0-9 will be deemed unsafe and be replaced with a “%” followed by the unsafe character’s hex equivalent. For instance spaces are replaced with %20 because the ASCII value of a space is 32 (0x20 in hex).






Function URLDecode()


Signature: URLDecode(cString)


Parameters:


cString – The string you want decoded (unescaped).


Return Value:


Character – returns the decoded equivalent of cString.


Remarks:


This function provides libcurl’s “URL Unescape” functionality. Any character in cString that has been escaped/encoded with a “%” followed by its hex equivalent will be decoded to its plaintext equivalent. For instance %20 will be turned back into a space – CHR(32).






Function SetConnectTimeout()


Signature: SetConnectTimeout(nSeconds)


Parameters:


nSeconds – The number of seconds any connection operation in VFPConnection should wait before failing due to timeout.


Return Value:


None


Remarks:


This function effects all connection operations in VFPConnection. The default value for the connection timeout is 10 seconds.




Function SetResponseTimeout()


Signature: SetResponseTimeout(nSeconds)


Parameters:


nSeconds – The number of seconds any operation in VFPConnection should wait for a response before failing due to timeout.


Return Value:


None


Remarks:


This function effects all operations in VFPConnection that are designed to wait for a server response. The default value for the response timeout is 10 seconds.






Function DateStrToEpochSec()


Signature: DateStrToEpochSec(cDateTime)


Parameters:


cDateTime – A datetime string in one of the many formats.


Return Value:


Numeric – returns the number of seconds between Epoch and the datetime specified by cDateTime.


Remarks:


This function is useful when attempting to convert datetime strings you may encounter when working with web-based applications. RFC2616 specifies which datetime string formats are acceptable for HTTP applications and, in short, there are a lot of them. For instance…


Sun, 06 Nov 1994 08:49:37 GMT
Sunday, 06-Nov-94 08:49:37 GMT
Sun Nov 6 08:49:37 1994
06 Nov 1994 08:49:37 GMT
06-Nov-94 08:49:37 GMT
Nov 6 08:49:37 1994
06 Nov 1994 08:49:37
06-Nov-94 08:49:37
1994 Nov 6 08:49:37
GMT 08:49:37 06-Nov-94 Sunday
94 6 Nov 08:49:37
1994 Nov 606-Nov-94
Sun Nov 6 94
1994.Nov.6
Sun/Nov/6/94/GMT
Sun, 06 Nov 1994 08:49:37 CET
06 Nov 1994 08:49:37 EST
Sun, 12 Sep 2004 15:05:58 -0700
Sat, 11 Sep 2004 21:32:11 +0200
20040912 15:05:58 -0700
20040911 +0200


…are all acceptable. There are also a number of situations where you may be required to use or know the number of seconds since midnight January 1, 1970 (a.k.a. epoch – due to unix and POSIX systems which count time this way). In any event, this function is provided as a crutch if needed.





Function CurlVersion()


Signature: CurlVersion()


Parameters:


None


Return Value:


String – the versions of libcurl and OpenSSL that were used in VFPConnection


Remarks:


This may be of some interest to VFP developers who are asking for enhancements or want to ensure that this library is using the latest and greatest. The static libraries for libcurl and OpenSSL were both built from the latest source available at the time using Visual Studio 2003 and ActivePerl.