|
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Using The Execute Method For most FTP commands, you must use the Internet Transfer controls Execute method. You saw this method used for HTTP transfers earlier in the chapter. With FTP, Execute is X
considerably simpler, because it uses only two of the arguments. For FTP tasks, therefore, the syntax of Execute is: Inet1.Execute (url, operation) The url argument is the URL of the FTP site, including directory, if desired. Operation is a string containing the FTP command and any needed parameters. This is how FTP works: The command and any needed parameters are always together in a single string, separated by a single space. Use the GetChunk method to obtain data returned by the FTP server. I explained how to use GetChunk earlier in the chapter; the techniques are the same for FTP as for HTTP. When working with FTP connections, keep these two points in mind:
An FTP Demonstration Perhaps the best way to understand using the Internet Transfer control for FTP transfers is to see it in action. The program presented in this section, FTP_DEMO, provides fundamental FTP capabilities in a relatively simple program. You can log on to any FTP server, either as a registered user or as an anonymous guest, and view a listing of the default directory. You can change to different directories, and you can download and upload files depending on your permission level. The program is shown in Figure 18.2. When programming the Internet Transfer control, you must pay strict attention to the StillExecuting property. Because the Execute method operates asynchronously, the control can still be busy executing the most recent Execute command, even though execution has returned to your program code. If your program tries to call Execute again, an error will occur. Therefore, you must check the status of the StillExecuting property and call Execute only when this property is False. You can see how I did this by looking at the listing for this program.
I called the program FTP_DEMO. Its objects and properties are given in Listing 18.5, and its code in Listing 18.6. I am not going to walk you through all the steps of creating this program, because you should have no problem understanding how the code operates. Be aware that FTP_DEMO is a bare-bones program; although it has basic error-handling capabilities, it has no provisions for user errors, such as trying to GET a nonexistent file. Also, there are no warnings about overwriting existing files, so use caution. Listing 18.5 Objects and properties in FTP_DEMO.FRM. Begin VB.Form Form1 Caption = FTP Demonstration StartUpPosition = 3 Windows Default Begin VB.CommandButton Command2 Caption = Change Dir Index = 2 End Begin VB.CommandButton Command2 Caption = Get Index = 1 End Begin VB.CommandButton Command2 Caption = Put Index = 0 End Begin VB.TextBox txtRemoteDir End Begin InetCtlsObjects.Inet Inet1 End Begin VB.TextBox txtRemoteFileName End Begin VB.TextBox txtLocalFileName End Begin VB.CommandButton Command1 Caption = Quit Index = 3 End Begin VB.CommandButton Command1 Caption = LogOff Index = 2 End Begin VB.CommandButton Command1 Caption = Refresh Index = 1 End Begin VB.CommandButton Command1 Caption = LogOn Index = 0 End Begin VB.TextBox txtDirectory Locked = -1 True MultiLine = -1 True ScrollBars = 3 Both End Begin VB.TextBox txtPassword End Begin VB.TextBox txtUserName End Begin VB.TextBox txtURL End Begin VB.Label Label6 Caption = Remote directory End Begin VB.Label Label5 Caption = Remote File Name End Begin VB.Label Label4 Caption = Local File Name End Begin VB.Label lblStatus ForeColor = &H000000FF& End Begin VB.Label Label3 Caption = Enter password, or your e-mail address for anonymous logon End Begin VB.Label Label2 Caption = Enter user name, or blank End Begin VB.Label Label1 Caption = Enter FTP server URL End End
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |