Difference between revisions of "Internet Transfer Control in VB6"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
m
Line 1: Line 1:
 
== Using the OpenURL Method to Retrieve an HTML Page ==
 
== Using the OpenURL Method to Retrieve an HTML Page ==
  
Example 1:
+
Example 1: VB6
  
 
   <nowiki>Private Sub cmdGo_Click()</nowiki>
 
   <nowiki>Private Sub cmdGo_Click()</nowiki>
Line 14: Line 14:
 
   <nowiki>End Sub</nowiki>
 
   <nowiki>End Sub</nowiki>
  
Example 2:
+
Example 2: VBA, Uses the internet transfer control with HTTP to create an HTML page.   
Uses the internet transfer control with HTTP to create an HTML page.   
+
  
 
   <nowiki>Dim objInet as Inet</nowiki>
 
   <nowiki>Dim objInet as Inet</nowiki>
Line 50: Line 49:
 
   <nowiki>  objInet.openURL objInet.URL, icByteArray</nowiki>
 
   <nowiki>  objInet.openURL objInet.URL, icByteArray</nowiki>
 
   <nowiki>  MsgBox objInet.GetHeader</nowiki>
 
   <nowiki>  MsgBox objInet.GetHeader</nowiki>
 +
  <nowiki>End Sub</nowiki>
 +
 +
Example 3: VBA, Retrieve a File from an FTP Site
 +
 +
  <nowiki>Private Sub Form_Load()</nowiki>
 +
  <nowiki>  ' Set a reference to the internet transfer control.</nowiki>
 +
  <nowiki>  Set objFTP = Me!axFTP.Object</nowiki>
 +
  <nowiki>End Sub</nowiki>
 +
  <nowiki></nowiki>
 +
  <nowiki>Private Sub cmdGetFile_Click()</nowiki>
 +
  <nowiki>  Dim strSite As String</nowiki>
 +
  <nowiki>  Dim strFile As String</nowiki>
 +
  <nowiki>  strSite = Me!txtFTPSite</nowiki>
 +
  <nowiki>  strFile = Me!txtFileName</nowiki>
 +
  <nowiki>  objFTP.Protocol = icFTP</nowiki>
 +
  <nowiki>  objFTP.URL = strSite</nowiki>
 +
  <nowiki>  objFTP.Execute strSite, "Get " & strFile & " C:\" & strFile</nowiki>
 +
  <nowiki>End Sub</nowiki>
 +
  <nowiki></nowiki>
 +
  <nowiki>Private Sub axFTP_StateChanged(ByVal State As Integer)</nowiki>
 +
  <nowiki>  ' Display a message when the transfer is finished.</nowiki>
 +
  <nowiki>  If State = 12 Then Msgbox "File Transferred"</nowiki>
 
   <nowiki>End Sub</nowiki>
 
   <nowiki>End Sub</nowiki>
  

Revision as of 14:52, 6 February 2008

Using the OpenURL Method to Retrieve an HTML Page

Example 1: VB6

 Private Sub cmdGo_Click()
   inet.Protocol = icHTTP
   inet.URL = txtAddress.Text
   txtOut.Text = inet.OpenURL
 
 End Sub
 
 Private Sub Form_Load()
   txtAddress.Text = "http://wiki.robotz.com"
 End Sub

Example 2: VBA, Uses the internet transfer control with HTTP to create an HTML page.

 Dim objInet as Inet
 
 Private Sub Form_Load()
    ' Set a reference to the internet transfer control.
    Set objInet = Me!axInetTran.Object
 End Sub
 
 Private Sub cmdWriteFile_Click()
    Dim b() as Byte
 
    ' Set the internet transfer control protocol and URL.
    objInet.Protocol = icHTTP
    objInet.URL = "HTTP://www.microsoft.com"
 
    ' Retrieve the HTML data into a byte array.
    b() = objInet.OpenURL(objInet.URL,icByteArray)
 
    ' Create a local file from the retrieved data.
    Open "C:\Homepage.htm" For Binary Access Write As #1
    Put #1, , b()
    Close #1
 
    MsgBox "Done"
 End Sub
 
 Private Sub cmdGetHeader_Click()
    ' Set the internet transfer control protocol and URL.
    objInet.Protocol = icHTTP
    objInet.URL = "HTTP://www.microsoft.com"
 
    ' Open the HTML and display the header information.
    objInet.openURL objInet.URL, icByteArray
    MsgBox objInet.GetHeader
 End Sub

Example 3: VBA, Retrieve a File from an FTP Site

 Private Sub Form_Load()
    ' Set a reference to the internet transfer control.
    Set objFTP = Me!axFTP.Object
 End Sub
 
 Private Sub cmdGetFile_Click()
    Dim strSite As String
    Dim strFile As String
    strSite = Me!txtFTPSite
    strFile = Me!txtFileName
    objFTP.Protocol = icFTP
    objFTP.URL = strSite
    objFTP.Execute strSite, "Get " & strFile & " C:\" & strFile
 End Sub
 
 Private Sub axFTP_StateChanged(ByVal State As Integer)
    ' Display a message when the transfer is finished.
    If State = 12 Then Msgbox "File Transferred"
 End Sub

 

FTP Files Using the Internet Transfer Control

You can easily FTP files between a client and host computer.

Port Service
21 File Transfer Protocol (FTP)
25 Simple Mail Transfer Protocol (SMTP)
79 Finger
80 Hypertext Transfer Protocol (HTTP)
443 Secure Hypertext Transfer Protocol (HTTPS)
666 DOOM multiplayer game port