#INCLUDE WCONNECT.h
SET PROCEDURE TO wwUtils ADDITIVE
SET CLASSLIB TO wwIPStuff ADDITIVE

CLEAR
o=CREATE("wwIPStuff")
SET MEMOWIDTH TO 200
*** Sending SMTP Mail
IF .T.
	o.cMailServer="mail.yourmailserver.com"    && or IP address "111.111.111.111"
	o.nConnectTimeout = 10
   	
	*** Optional - Authentication
	* o.cUsername = "ricks"
    * o.cPassword = "supersecrete"
	
	o.cSenderEmail="bbopp@somewhere.com"
	o.cSenderName="Bill Bopp"
   o.cRecipient = "jwest@mysoft.com"
    
   *** ccLists
   * o.cCCList = ["John Doe" <rstrahl@doeboy.com>,"Jim Diddly" <jdid@lowermind.com>]
   * o.cBCCList = ["John Doe" <rstrahl@doeboy.com>,"Jim Diddly" <jdid@lowermind.com>]
   
	* o.cExtraheaders = o.cExtraHeaders + ;
   *    [Reply-To: "Rick Strahl" <rickstrahl@hotmail.com>] +CRLF 

	*** Optional Return Receipt
   * o.lReturnReceipt = .t.

	o.cSubject="wwIPStuff Test Message"
	o.cMessage="Who said this had to be difficult?"

   *** Send Html Email - if you've formatted full HTML in cMessage
   * o.cContentType="text/html"

 	*** Optional Attachement(s)
    * o.cAttachment = "d:\temp\Html Text.txt,d:\temp\Html Text.htm"
   
	llResult = o.SendMail()       && Send again - wait for completion
	IF !llResult
	   Wait window o.cErrorMsg
	ELSE
	   Wait window nowait "Message sent..."
	ENDIF

	*** Or you can send without waiting for completion but without confirm of send action
	* o.SendMailAsync()    && Send message and return immediately w/o result

	RETURN
ENDIF	
	
*** FTP transfers	
IF .F.
    o=CREATE("wwFTP")
    
*    wait window nowait "Downloading pkzip to c:\temp"
	? o.FTPGetFile("ftp.west-wind.com","/","c:\temp\wcreadme.txt")

	*** Or you can use syntax like this:
	o.cFTPServer="ftp.west-wind.com"
	o.cFTPSource="c:\icsapilog.txt"
	o.cFTPTarget="/uploads/iscapilog.txt"

	*** Use passwords if Anonymous is not allowed.
	* o.cUsername="username"      
	* o.cPassword="password"

    wait window nowait "Attempting to send file..."
	? o.FTPSendFile()
	if o.nError # 0
	   ? o.cErrorMsg
	   * ? o.GetLastInternetError(12003)
	endif
	
*!*	   DIMENSiON laFiles[1]
*!*	   lnFiles = o.aFTPDir(@laFiles, "ftp.west-wind.com", "/wwwreg/*.*")  &&, lcUsername, lcPassword
*!*	   for x= 1 to lnFiles
*!*	      ? laFiles[x]
*!*	   endfor
	
ENDIF

*** Simple HTTP GET	
IF .F.
  loHttp = CREATEOBJECT("wwHttp")
  ? loHttp.HTTPGet("http://www.west-wind.com/")
  lcData=loHttp.HTTPGet("http://www.west-wind.com/files/wwipstuff.zip")
  ? lcData
ENDIF  

*** POSTing data
IF .F.
   loHttp = CREATEOBJECT("loHttp")

    wait window nowait "Running HTTP request to get all A's from the detail list..."
	loHttp.AddPostKey("Client","B")
	loHttp.AddPostKey("FromDate","01/01/96")

    *** Preset the buffer and result size
	lcText=""
	lnText=0

	*** Send the POST data and retrieve HTTP result
   lcText = loHttp.HTTPGet("http://www.west-wind.com/wconnect/wc.dll?wwDemo~ShowHours")
   ? loHttp.nError  && 0 - no error   > 0 - Error Code
   ? loHttp.cErrorMsg
   ? lcText
ENDIF

IF .F.	
     loHttp = CREATEOBJECT("loHttp")

	
	   *** Read the results send by the server - result is encoded file
	   lcText = loHttp.HTTPGetEx("/wconnect/wc.dll?http~SendCustList4")

      
	   *** decode the file and save to Timport.dbf
	   IF loHttp.DecodeDBF(lcText,"Timport.dbf")
	      *** Show the result
	      USE Timport
	      BROWSE TITLE "Downloaded Customer List"
	   ELSE
	      wait window "File could not be converted"
	   ENDIF
ENDIF
	
*** Domain Name Lookup
IF .F.
	*** Domain Lookups from IP Address and Reverse Domain Lookups
	? o.GetDomainFromIp("205.162.195.2")
	? o.GetIpFromDomain("www.microsoft.com")
ENDIF	


*** Running Queries over HTTP from a VFP client!

IF .F.
	*** Demonstrate Uploading a file generically
	*** NOTE: you have to enable the wwHTTPData request
	***       in wcmain in wcDemoServer::Process by uncommenting
	***       the CASE lcParameter = "WWHTTPDATA" block
	o=CREATE("wwHTTPData")
	o.cServername = "localhost"
	o.nMaxBufferSize = 100000
	o.cUsername = "yourusername"
	o.cPassword = "loser"
	o.lIsZipped = .F.
	
	o.cSQL = [Insert INTO Guest ('Name','company') values ('rick]+chr(0)+[s','West Wind')]
*	o.cSQL = "SELECT * FROM Tt_cust" 
	o.Execute()

	IF o.lError
	  ? o.cSQL
	  ? o.cErrorMsg
	  RETUR
	ENDIF

	BROWSE

    *** You can also do inserts and Updates like this
	*!*	o.cSQL = [INSERT INTO Timebill (custno) VALUES ("123123")]
	*!*	o.Execute()

	*!*	IF o.lError
	*!*	  ? o.cSQL
	*!*	  ? o.cErrorMsg
	*!*	ENDIF
ENDIF


*** Sending Files via HTTP from a VFP client 

IF .F.
	*** Demonstrate Uploading a file generically
	*** NOTE: you have to enable the wwHTTPData request
	***       in wcmain in wcDemoServer::Process by uncommenting
	***       the CASE lcParameter = "WWHTTPDATA" block
	o=CREATE("wwHTTPFile")
	o.cServername = "localhost"
	o.nMaxBufferSize = 100000
	o.cUsername = "rstrahl"
	o.cPassword = "loser"
	o.lIsZipped = .T.
	o.cSourceFile = "c:\wwapps\wc2\wcmain.prg"
	o.cTargetFile = "c:\temp\wconnect.h"
	o.cHTTPLink = "/wconnect/wc.dll?wwHTTPData~SendFile"
	o.SendFile()

	IF o.lError
	  ? o.cErrorMsg
	  RETUR
	ENDIF

ENDIF

*** Remote COM object invokation
IF .T.
   o = CREATE("wwHTTPCOM")
   o.cServerName = "localhost"
   o.cHTTPLink = "/wconnect/wc.dll?wwHTTPData~HTTPCom"
   lcResult = o.Execute("visualfoxpro.application","Eval('sys(0)')")
   IF o.lError
      ? o.cErrorMsg
   ELSE
      ? lcResult
   ENDIF
   
   ? "XML output: "
   ? o.cResultBuffer

   *** You can also post data directly as XML without
   *** the wwHTTPData class on the client:
*!*	   lcXML = ;   
*!*			[<?xml version="1.0" ?>] + CR + ;
*!*			[<httpcom>] + CR + ;
*!*			[   <progid>visualfoxpro.application</progid>] + CR + ;
*!*			[   <method>eval(' sys(0) ')</method>] + CR + ;
*!*			[</httpcom>] + CR 

*!*	    o=CREATE("wwIPStuff")
*!*	   
*!*	    o.httpconnect("localhost")
*!*	    
*!*	    lcResultXML = ""
*!*	    lnSize = 0
*!*	    
*!*	    o.AddPostKey("",lcXML)
*!*	    
*!*	    lnResult = o.httpgetex("/wconnect/wc.dll?wwhttpdata~httpcom",@lcResultXML,@lnSize)
*!*	    IF lnResult # 0
*!*	       ? o.cERrorMsg
*!*	       RETURN
*!*	    ENDIF
*!*	    
*!*	    *** lcData will receive Result XML
*!*	    ? lcResultXML
*!*	    
*!*	    oXML = Create("wwXML")
*!*	    lcResult = oXML.GetObjVar("ComResult",lcResultXML)
*!*	    ? lcResult
    
   

ENDIF   
