FTP w/ VB6 For begginers
Posted: Sat Jul 30, 2005 2:55 pm
Alrite, I will show you how to make a very basic FTP program in VB6.
1)Open up VB6, and Press Ctrl-T to open up components window.
2)Go Down to "Microsoft Internet Transfer Controls", select it, then hit Ok!
3)Make 5 Textboxes , and 2 buttons. Name the textboxes
txthost.text
txtusername.text
txtpass.text
txtremotefile.txt
txtlocalfile.txt
Then for caption for the 2 command buttons, have one Upload and the other Download..
Now you can make labels next to the textboxes, but basically its self-explanitory except for txt.host.text is where you input the URL
4) First of all we will code the download button.
I will walk you through the code
Drag the inet1 from the toolbar into you form, and change the protocol to "2 icFTP".
This just means that you declare the variable HostName as a string. Which means it will be letters/words. String is just basically a sentence.
That assigns the contents of everything in the txthost.text textbox to the HostName variable.
This is probably the trickiest part of the whole, code. Although it is not required. It sure does help clear a big error out of the way.
let me explain syntax here
To check out the defintions of Vb6 syntax please visit
Here
Lcase$() ---Puts everything inside the brackets into lowercase. Because textboxes are case-sensitive, we need to make it inside the case. The $ sign only means that it is a string, just to clarify and make it run faster.
Left$()---This returns a letters/words, from the left. Best way to explain this is with another example. Left$("Superman", 5). That will display 5 letters from the left. So it would return "Super"
Now that i cleared up the functions meanings I can go ahead and explain the line of code. If 6 letters from the left DO NOT equal (<>) "ftp://" then HostName = "ftp://" and the url text box.
Anyway, continuing with the code..
That just assigns the textbox information to inet1. Which is what will FTP.
Here is the last line of code for download!
Now this tells inet1 to get the file (directory/file declared by txtremote.text) file, and save it as (declared where on your pc you wil like it and the name Directory/name) file on your pc.
Now Uploading is the exact same thing except for the last line, so I will just post the whole code for upload
Now that you have the basic stuff. You can add error support, and status of the Transfer/connection.!
1)Open up VB6, and Press Ctrl-T to open up components window.
2)Go Down to "Microsoft Internet Transfer Controls", select it, then hit Ok!
3)Make 5 Textboxes , and 2 buttons. Name the textboxes
txthost.text
txtusername.text
txtpass.text
txtremotefile.txt
txtlocalfile.txt
Then for caption for the 2 command buttons, have one Upload and the other Download..
Now you can make labels next to the textboxes, but basically its self-explanitory except for txt.host.text is where you input the URL
4) First of all we will code the download button.
I will walk you through the code
Drag the inet1 from the toolbar into you form, and change the protocol to "2 icFTP".
Code: Select all
dim HostName as string
Code: Select all
HostName = txthost.Text
Code: Select all
If LCase$(Left$(hostname, 6)) <> "ftp://" Then hostname = "ftp://" & txthost.Text
let me explain syntax here
To check out the defintions of Vb6 syntax please visit
Here
Lcase$() ---Puts everything inside the brackets into lowercase. Because textboxes are case-sensitive, we need to make it inside the case. The $ sign only means that it is a string, just to clarify and make it run faster.
Left$()---This returns a letters/words, from the left. Best way to explain this is with another example. Left$("Superman", 5). That will display 5 letters from the left. So it would return "Super"
Now that i cleared up the functions meanings I can go ahead and explain the line of code. If 6 letters from the left DO NOT equal (<>) "ftp://" then HostName = "ftp://" and the url text box.
Anyway, continuing with the code..
Code: Select all
Inet1.URL = hostname
Inet1.UserName = txtusername.Text
Inet1.Password = txtpass.Text
Here is the last line of code for download!
Code: Select all
Inet1.Execute , "Get " & txtremote.Text & " " & txtlocal.Text
Now Uploading is the exact same thing except for the last line, so I will just post the whole code for upload
Code: Select all
Dim hostname As String
hostname = txthost.Text
If LCase$(Left$(hostname, 6)) <> "FTP://" Then hostname = "ftp://" & txthost.Text
Inet1.URL = hostname
Inet1.UserName = txtusername.Text
Inet1.Password = txtpass.Text
Inet1.Execute , "Put " & txtlocal.Text & " " & txtremote.Text