• Welcome to PowerBasic Museum 2020-A.
 

INET: Microsoft Internet Transfer Protocol Control

Started by José Roca, December 18, 2008, 12:49:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The Internet Transfer control implements two widely-used Internet protocols: the HyperText Transfer Protocol (HTTP) and the File Transfer Protocol (FTP). Using the Internet Transfer control, you can connect to any site that uses one of these protocols, and retrieve files using either the OpenURL or Execute method.

Possible Uses



  • To add an FTP browser to any application.

  • To create an application that automatically downloads files from a public FTP site.

  • To parse a World Wide Web site for graphics references and download the graphics only.

  • To present a custom display of dynamic data retrieved from a Web page.

The following examples demonstrates how to create a registration-free instance of the Microsoft Internet Transfer Protocol Control.

Registration-free means that you don't need to register the control to be able to use it. To use this registration-free version, you must copy MSINET.OCX in the application folder, as if it was an standard DLL.

For using a registered version of the control, change the following code in the examples:


pINet = CreateInstanceFromDll(EXE.Path$ & "MSINET.OCX", $CLSID_Inet, $IID_IInet, $RTLKEY_INET)



pINet = NEWCOM "INetCtls.INet.1"


Full example code:


' ########################################################################################
' This example downloads the PowerBasic forum main page.
' ########################################################################################

#COMPILE EXE
#DIM ALL

#INCLUDE ONCE "msinet.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pINet AS IInet
   LOCAL strURL AS STRING
   LOCAL vRes AS VARIANT
   LOCAL strText AS STRING

   pINet = CreateInstanceFromDll(EXE.Path$ & "MSINET.OCX", $CLSID_Inet, $IID_IInet, $RTLKEY_INET)
   IF ISNOTHING(pInet) THEN EXIT FUNCTION
   
   pINet.AccessType = %icDirect
   pINet.Protocol = %icHTTP
   pINet.RemotePort = 80
   pINet.RequestTimeout = 60
   strURL = "http://www.powerbasic.com/"
   vRes = pINet.OpenURL(strURL, %icString)
   MSGBOX VARIANT$(vRes)
   strText = pINet.GetHeader("Server")
   MSGBOX ACODE$(strText)
   strText = pINet.GetHeader("Date")
   MSGBOX ACODE$(strText)
   strText = pINet.GetHeader("Content-type")
   MSGBOX ACODE$(strText)

   pINet = NOTHING

END FUNCTION
' ========================================================================================



Full example code:


' ########################################################################################
' This example downloads IncLean.zip and saves it to disk.
' ########################################################################################

#COMPILE EXE
#DIM ALL

#INCLUDE ONCE "msinet.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pINet AS IInet
   LOCAL strURL AS STRING
   LOCAL vRes AS VARIANT

   pINet = CreateInstanceFromDll(EXE.Path$ & "MSINET.OCX", $CLSID_Inet, $IID_IInet, $RTLKEY_INET)
   IF ISNOTHING(pInet) THEN EXIT FUNCTION

   pINet.AccessType = %icDirect
   pINet.Protocol = %icHTTP
   pINet.RemotePort = 80
   pINet.RequestTimeout = 60
   strURL = "http://www.powerbasic.com/files/pub/pbwin/tools/inclean.zip"
   vRes = pINet.OpenURL(strURL, %icByteArray)
   DIM a(0) AS BYTE
   a() = vRes
   OPEN "IncLean.zip" FOR BINARY AS #1
   PUT #1, 1, a()
   CLOSE #1
   MSGBOX "Done!"

   pINet = NOTHING

END FUNCTION
' ========================================================================================