Previous Page
Next Page

Hack 99. Download Files Using the Web Browser Control

FTP files without ever leaving your database.

"Use a Browser Inside Access" [Hack #97] and "Pull the HTML Source Code from a Web Site" [Hack #98] show you how to browse the Web from an Access form and how to retrieve the source HTML code. This hack shows you how to use the Web Browser control to pull files from an FTP site.

The File Transfer Protocol (FTP) is commonly used to move files to and from a web server. Often, the site is password-protected, so to try out this hack, you need the rights to access an FTP site.

10.5.1. Placing the Web Browser Control on a Form

As discussed in "Use a Browser Inside Access" [Hack #97], you can place the Microsoft Web Browser control on a form. The Navigate method takes a URL address to navigate to. In this hack, an FTP URL is supplied instead of an HTTP URL.

Using a line of code such as the following, the Web Browser control opens a login dialog (shown in Figure 10-9):

    Me.WebBrowser0.Navigate URL:="ftp.logicstory.com"

Figure 10-9. Entering a username and password for the FTP site


After the login is complete, the Web Browser control displays the site's contents. You can view, copy, delete, and rename objects depending on your user permissions, as shown in Figure 10-10.

Figure 10-10. Viewing contents of the web site


When you select a file to copy, the Copy Items dialog displays the filesystem on the local computer. A directory is selected where the copied file will be pasted, as shown in Figure 10-11.

Figure 10-11. Selecting the local directory to save the copied file


10.5.2. Uploading Files

As noted earlier, when selecting a file to download, the "Copy this item" link opens the Copy Items dialog box. Although no equivalent link is available for initiating an upload, you can upload files to the FTP site. All you have to do is select the file on the local machine, and then click once in the Web Browser control and use the paste keyboard shortcut (Ctrl-V). Figure 10-12 shows the progress of a copy operation, confirming that a file is being copied to the site.

Figure 10-12. Copying a file to the remote server


    Previous Page
    Next Page