Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Modules: Internet Data Transfer Library

Author(s)
Dev Ashish

INFORMATION PROVIDED IN THIS DOCUMENT AND THE INTERNET DATA TRANSFER LIBRARY ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED. THE USER ASSUMES THE ENTIRE RISK OF RUNNING THIS SOFTWARE.

Dev Ashish (1998-2004), All Rights Reserved

The InetTransferLib can be used to transfer binary or text files to and from web servers which support HTTP and FTP protocols.

The library is distributed as a Microsoft Access 97 Addin (MDA) file which can be referenced in your projects. It uses the API functions stored in WinInet.dll which is installed by Microsoft Internet Explorer.

To use this functionality in Microsoft Access 2000 or higher, please import all the classes from the addin (which does not have the tables required for a typical Access addin) in your own Access project. To use the classes, just refer to them with the 'InetTransferLib.' prefix (eg: Dim objHTTP As HTTP)

The InetTransferLib exposes two object, HTTP and FTP. The use of the objects will be dependent on the protocol through which you wish to transfer files.

The documentation for individual methods and properties for the objects can be viewed by bringing up the Object Browser and selecting the library.

An additional database, InetTransfer Sample.mdb, is included in the zip file to provide usage samples.

When using the exposed objects, you must include error handling in your code.

If you need to import the objects into your database, make sure you import the cDialog class as well.

Download Download InetTransferLib.zip (327,680 bytes)

A beta version of version 2 of the library, wrapped in a VB 6 COM object, is also available for download.  Please note that this version has not been fully tested and is as unsupported as the previous version. But, it does offer more functionality, like:
  • HTTP: Reading, or saving, the entire HTML as a string or a file.
  • HTTP: SSL support.
  • HTTP: Querying for header information.
  • HTTP: Adding custom headers
  • HTTP: POST support.
  • FTP: Create remote directory
  • FTP: Delete remote file
  • FTP: Rename remote file
  • FTP: Enumerate remote folders

Please see the test project for code samples on how to use the class.

Download Download InternetTransferLib.zip; Beta version. (Requires VB 6 Runtime)

HTTP
-------

The HTTP object provides download only capabilities and can be used to download a file from any HTTP server, provided that you know the correct URL.

If you do not provide a DestinationFile for the object, and set the PromptWithCommonDialog property to True, the object will bring up the standard Windows GetSaveFileName dialog so that you can specify the local file name.

If you are not connected to a network and are using Windows Dial Up Networking to establish a TCP/IP connection, you can additionally check for a live connection by checking the IsConnected property. 

You can also retrieve the text from a target HTML or text file by using the WriteHTTPDataToString method. This method will return the contents of the specified URL in string format so that you can parse out the results without creating a local file.

The object can be used as

'*********** Code Start *************
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Sub TestHTTP()
On Error GoTo ErrHandler
Dim objHTTP As InetTransferLib.HTTP
Const conTARGET = "http://www.mvps.org/access/acknowledge.htm"

  Set objHTTP = New InetTransferLib.HTTP
  With objHTTP
    .About
    .HttpURL = conTARGET
    '.DestinationFile = "j:\temp\test.htm"
    .PromptWithCommonDialog = True
    If .FileExists Then .OverwriteTarget = True
    If Not .IsConnected Then .DialDefaultNumber
    .ConnectToHTTPHost
    .WriteHTTPDataToFile
  End With
ExitHere:
  On Error Resume Next
  Set objHTTP = Nothing
  Call SysCmd(acSysCmdRemoveMeter)
  Exit Sub
ErrHandler:
  MsgBox Err.Number & vbCrLf & Err.Description, _
         vbCritical + vbOKOnly, Err.Source
  Resume ExitHere
End Sub
'*********** Code End *************

FTP
-----

The FTP object provides both download and upload capabilities against a server which supports FTP capabilities. 

If you do not provide a DestinationFile/SourceFile for the object, and set the PromptWithCommonDialog property to True, the object will bring up the standard Windows GetSaveFileName/GetOpenFileName dialog respectively so that you can specify the local file name.

If you are not connected to a network and are using Windows Dial Up Networking to establish a TCP/IP connection, you can additionally check for a live connection by checking the IsConnected property. 

The object can be used to download a file from a FTP server as

'*********** Code Start ************
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Sub TestFTP()
On Error GoTo ErrHandler
Dim objFTP As InetTransferLib.FTP
Const conTARGET = "ftp://ftp.microsoft.com/softlib/softlib.exe"

  Set objFTP = New InetTransferLib.FTP
  With objFTP
    .UseProxy = True
    .FtpURL = conTARGET
    .DestinationFile = "h:\temp\test.exe"
    'If .FileExists Then .OverwriteTarget = True
    .PromptWithCommonDialog = True
    If Not .IsConnected Then .DialDefaultNumber
    .ConnectToFTPHost
    .WriteFTPDataToFile
  End With
ExitHere:
  On Error Resume Next
  Set objFTP = Nothing
  Call SysCmd(acSysCmdRemoveMeter)
  Exit Sub
ErrHandler:
  MsgBox Err.Number & vbCrLf & Err.Description, _
        vbCritical + vbOKOnly, Err.Source
  Resume ExitHere
End Sub
'********** Code End ****************

For file uploading, you can use the FTP object as follows. Note that setting SourceFile property to vbNullString will bring up the standard Windows GetOpenFileName dialog so that you or the user may select the file to upload to the FTP Server.

You must supply the Username and Password arguments of the ConnectToFTPHost method to ensure successful login to the server.

Under most circumstances, the UserName argument automatically sets the home directory on the server. Therefore, you would not need to include the user's home directory in DestinationFile property. For example, if you want to transfer a file "something.txt" to your home directory at server ftp.someServer.com, the DestinationFile property should be "/something.txt" instead of "/YourUserName/something.txt". 

If the AutoCreateRemoteDir property is set to True, the FTP Object will automatically create any folders specified in DestinationFile property, otherwise a runtime error will be raised if the object does not find the specified folder in the server's login home directory. The check is performed once for each folder specified in DestinationFile property.

'********** Code Start ****************
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Sub TestFTPUpload()
On Error GoTo ErrHandler
Dim objFTP As InetTransferLib.FTP
Const conTARGET = "ftp://ftp.someserver.com"

  Set objFTP = New InetTransferLib.FTP
  With objFTP
    .FtpURL = conTARGET
    .SourceFile = vbNullString
    .DestinationFile = "/2/test.txt"
    .AutoCreateRemoteDir = True
    If Not .IsConnected Then .DialDefaultNumber
    .ConnectToFTPHost "username", "password"
    .UploadFileToFTPServer
  End With
ExitHere:
  On Error Resume Next
  Set objFTP = Nothing
  Call SysCmd(acSysCmdRemoveMeter)
  Exit Sub
ErrHandler:
  MsgBox Err.Number & vbCrLf & Err.Description, _
       vbCritical + vbOKOnly, Err.Source
  Resume ExitHere
End Sub
'********** Code End ****************

Contact Information
---------------------------

If you have any comments or suggestions then you can contact me.


1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer