# Friday, December 05, 2008

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.

Friday, December 05, 2008 3:54:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [15]
Monday, December 08, 2008 12:22:19 AM (GMT Standard Time, UTC+00:00)
Great stuff!

Just one thing - for some reason your posts are now showing as one unbroken clump of text in FeedDemon. I haven't tried another RSS Aggregator but I assume that sometihng about your RSS feed has changed (in a bad way)?
Jamie Osborn
Friday, December 12, 2008 10:59:28 AM (GMT Standard Time, UTC+00:00)
Great Library.
But this new version don´t work correctly to download large files from FTP site (Aprox. 14 Mb).
The old version works fine.

Wednesday, December 17, 2008 12:58:23 AM (GMT Standard Time, UTC+00:00)
Excellent !!!! I search this solution for a long time.. I need secure FTP for send file to one server.
Thank you.
Diego
Thursday, December 18, 2008 11:56:03 AM (GMT Standard Time, UTC+00:00)
For some reason, this doesn't work for me. My FTP site isn't a normal one where the user name contains the URL so trying to do a:

FTP://user@user.com:userpassword@ftpsite.com

just errors out.

This is one of the reasons I continue to use the ww FTP class which never seems to fail.
Monday, December 29, 2008 12:10:11 PM (GMT Standard Time, UTC+00:00)
@Andrew

Did You try to URLEncode the Username/password?

I think

FTP://user%40user.com:username@ftpSite.com

should work
Monday, December 29, 2008 1:13:28 PM (GMT Standard Time, UTC+00:00)
I've been trying to get access to a secure ftp site (ie; SFTP://...) and I can't make it work. Do you happen to know if cURL works with those sites?
Hugh Winters
Friday, February 13, 2009 12:49:34 PM (GMT Standard Time, UTC+00:00)
Excellent library! Works in allmost all cases, but as I testd it yesterday on Vista machine behind proxy, it does not work!
I tried:
========
SET LIBRARY TO (LOCFILE("vfpconnection.fll","FLL"))
?CurlVersion()
?FTPGet("http://www.betanews.com","d:\cus.htm", "MyProgress()", "MyTrace()")
=========
What is wrong with it?
Sincerily Marek W
Marek W
Thursday, February 26, 2009 1:24:11 PM (GMT Standard Time, UTC+00:00)
hi

thank you very much
even what was needed...

however i have some problems with ftp!!!

SET LIBRARY TO (LOCFILE("c:\edi\vfpconnection.fll","FLL"))
?FTPGet("FTP://utilizador:edi@ftp.ftp.pt/out/recebe.zip", "C:\edi\recebe.zip", "MyProgress()", "MyTrace()")

i connect to ftp but do'nt recived the file and mytrace report timeout was reached.

can you please help me?

best regards
josé costa
Tuesday, March 03, 2009 12:33:18 AM (GMT Standard Time, UTC+00:00)
hello again

in the last post i said i have problems but now, they are solved.

how can i do this?

i do'nt know the names of the files in ftp, however all files are .xml.
can i get all files of this type to a directory?

i've the some problem to put, but i develop a solution that mount a cursor with all files and i put them
individualy on ftp, thanks to you, i try 3 times put them and if fail, i send an email to solve the problem.

it works very fine and never recived the mail.
can yoy help me pleased?

thnaks in advanced.

best regards


jose costa
Friday, March 06, 2009 11:10:55 AM (GMT Standard Time, UTC+00:00)
Can You help me?
I have still this problem, how can I use this library when my client is using proxy server (CISCO)?
Marek W
Wednesday, September 30, 2009 3:14:44 PM (GMT Daylight Time, UTC+01:00)
Craig,

Does each call to the library establish a new ftp connection and then disconnect... or will subsequent calls use an existing connection?

e.g. can i use ftpcommand to set PASV then call ftpPUT (to the same server obviously).

If not, how do i send a file with passive ftp?

thanks

Nigel
Friday, October 02, 2009 4:04:51 PM (GMT Daylight Time, UTC+01:00)
Hi

I've had a problem with this latest version on vfpconnection( 808Kb 05/12/2008 ) whereby it fails to download a zip file correctly when using ftpget and httpget. The program returns false and only partially downloads the file.

Using a previous version (176Kb 14/02/2008) that came with the AppUpdate the download works fine.

Has anyone else had a problem?

Regards

Keith
Tuesday, October 27, 2009 10:29:55 PM (GMT Standard Time, UTC+00:00)
Is there a way to Cancel/Abort an operation -- i.e., include a Cancel option in MyProgress()?
Mark S. Winston
Wednesday, December 09, 2009 9:10:04 PM (GMT Standard Time, UTC+00:00)
Hi, How i can cancel a download using this library? for example when I download a very big file (or a very slow connection), i need cancel de process

Thanks

Daniel
Daniel Salazar
Tuesday, March 09, 2010 11:47:12 AM (GMT Standard Time, UTC+00:00)
Hi

I've had also a problem with this latest version on vfpconnection( 808Kb 05/12/2008 ). The program returns false and only partially downloads the file.

Regards
Kalpesh
Kalpesh Chhatrala
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview

 

Archive

<December 2014>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910