Page 1 of 1

FTP w/ VB6 For begginers

Posted: Sat Jul 30, 2005 2:55 pm
by twolvesfan369
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".

Code: Select all

dim HostName as string
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.

Code: Select all

HostName = txthost.Text
That assigns the contents of everything in the txthost.text textbox to the HostName variable.

Code: Select all

If LCase$(Left$(hostname, 6)) <> "ftp://" Then hostname = "ftp://" & txthost.Text
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..

Code: Select all

Inet1.URL = hostname
Inet1.UserName = txtusername.Text
Inet1.Password = txtpass.Text
That just assigns the textbox information to inet1. Which is what will FTP.

Here is the last line of code for download!

Code: Select all

Inet1.Execute , "Get " & txtremote.Text & " " & txtlocal.Text
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

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
Now that you have the basic stuff. You can add error support, and status of the Transfer/connection.!

Posted: Tue Aug 02, 2005 6:35 pm
by twolvesfan369
32 views..not 1 comment?

Posted: Tue Aug 02, 2005 10:47 pm
by xxANTMANxx
great tut it helped me!

Posted: Sat Aug 06, 2005 6:51 am
by looknbarrel
lol this part of the forums died if you havent noticed but very good tutorial

Posted: Sat Aug 20, 2005 3:52 am
by BlairBitch
hey good tut but win ever i try to ftp i get Run-time error 424 object requierd did i do som thing wrong or maby im filling out the 5 tex boxes wrong im trying to ftp into my xbox so were url is i poot 192.168.1.102 then for user name and pass i poot xbox but im not to sure wat i poot for the last to

Posted: Sat Nov 26, 2005 4:18 pm
by superaison
meh this is a huge bump, anyway is there by anychance someone can get this into vb 2005? cuz i just got it to work today