|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Uploading Online Registration Information To An FTP ServerIn the previous topic, weve stored the registration information we want to upload to the FTP server in a file, temp.dat. To upload the user registration data, we add an Internet transfer control, Inet1, to the onlinereg applications registration form, Form2 (see Chapter 21 for more details on the Internet transfer control). After writing the registration form to disk, we connect to the FTP server to upload the data to by using the Internet transfer control like this, where we set the controls URL property to the address of the FTP server and set the UserName and Password properties as required:
Private Sub Command1_Click()
Open "c:\temp.dat" For Output As #1
Print #1, "Registering SuperDuperDataCrunch" & vbCrLf
Print #1, "Name: " & Text1.Text & vbCrLf
Print #1, "email: " & Text2.Text & vbCrLf
Print #1, "Time: " & Format(Now)
Close #1
Inet1.URL = "ftp://ftp.server.com"
Inet1.UserName = "steve"
Inet1.Password = "secret"
...
Here we are using the connection protocol used by many FTP servers, which sets the current FTP directory based on the username you log in with. If you need to set the current directory yourself, use the FTP CD command, using the Internet transfer controls Execute method.
To actually upload the file temp.dat, we use the Internet transfer controls Execute method to execute the FTP Put command like this, where we name the file reg.dat when uploaded to the server:
Private Sub Command1_Click()
Open "c:\temp.dat" For Output As #1
Print #1, "Registering SuperDuperDataCrunch" & vbCrLf
Print #1, "Name: " & Text1.Text & vbCrLf
Print #1, "email: " & Text2.Text & vbCrLf
Print #1, "Time: " & Format(Now)
Close #1
Inet1.URL = "ftp://ftp.server.com"
Inet1.UserName = "steve"
Inet1.Password = "secret"
Inet1.Execute , "PUT c:\temp.dat reg.dat"
End Sub
This uploads the file with the user registration information to the FTP site youve selected: Registering SuperDuperDataCrunch Name: steve email: steve@steveco.com Time: 5/5/99 10:02:23 AM
Now that weve uploaded the registration data, we need to terminate the FTP connection and delete the temporary file, and well do that in the next topic. Concluding The FTP Transfer Of The Online Registration InformationIn the previous few topics, weve sent user registration data to an FTP site in the onlinereg application. Now that the upload operation is complete, we will close the FTP connection in the Internet transfer controls StateChanged event handler:
Private Sub Inet1_StateChanged(ByVal State As Integer)
If State = icResponseCompleted Then
Inet1.Execute , "Close"
...
In addition, we delete the temporary file weve created and hide the registration form this way:
Private Sub Inet1_StateChanged(ByVal State As Integer)
If State = icResponseCompleted Then
Inet1.Execute , "Close"
Dim FileSystemObject As Object
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
FileSystemObject.DeleteFile "c:\temp.dat"
Form2.Hide
End If
End Sub
And thats itweve uploaded the user registration data to the specified FTP site. Congratulations, now youre supporting online registration. The code for this example is located in the onlinereg folder, and the code that displays that form is located in the Form1 folder, both on this books accompanying CD-ROM.
|
|
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. |