dear sir,
question 1
l want to write a simple ftp program that use the inet control, l would like to allow the user to enter their username and password, then connect to ftp server, l would like to determine the response from ftp server if the username and password is invalid, should l use "icError" or "icDisconnecting" ?       

question 2
sorry for this simple question, because l doesn't found any help in online book and help. my problem is l would like to write a ftp program, l've already filled in all the properties value like url, password,username and so on. then how to connect to ftp server ? l cannt found any specification in online book that teach how to connect. it just specified that how to execute and openurl. Please help, anyhelp would be appreciate.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

johnny_5Connect With a Mentor Commented:
Heya there...

Okay - the Inet control is nothing special.  You can do with the Winsock control what you can with the inet control, for the most part, and have much more control - however, most people don't like to write the interpreters for the basic protocol responses, so.  

Here's how you do it -

properties -
      RemoteHost -
            (the dns name or ip address of the server)
      RemotePort - 21 (the ftp port)
      Username   - joe
      Password   - 123

This will automatically fill in the URL property to read like this:

A word about URL's - Uniform Resource Locator.  The idea is that a URL can be used across different protocols to locate specific resources.  What's in a name?  However, some resources are more closely guarded than others, they require passwords, etc.  (Most) every ftp server requires a username and password of some sort.  When you look at ftp directories through netscape, you're actually sending a username and password of some sort - I think "Mozilla" is the username and it uses your email for password, of just some nonesuch.  Anyways - the point is that you include a username and password in a url using the format above.  Furthermore, you specify directories, etc. as well through the url, all the way down to the filename you want to get.  You can't send commands through a web browser (necessarily, normally at least) but that's why you're making a program, right?

Okay - here's the setup.

you have Text1 with the url, including username and password, like so:

Now, you put code somewhere (usually behind a command button) that says
      On error resume next
      inet1.execute text1.text

Don't go runnin' it yet - you have no way to get any data back.

First of all, to answer one of your questions, you know that you have an incorrect password when you can't connect.  That's what the "On error resume next" is for - so that your program will keep going and you can handle the error where you're supposed to, in the StateChanged event...

For a list of all the possible states, hit F1 on yer inet control and look at the statechanged event, or hit F2 and look at the inetobjects whatever library under State Constants.  

Here I'll only talk about two - icError(11) and icResponseCompleted(12).

Private Sub Inet1_StateChanged(ByVal State As Integer)
    ' Retrieve server response using the GetChunk
    ' method when State = 12.

    Dim vtData As Variant ' Data variable.
    Select Case State
    ' ... Other cases not shown.
    Case icError ' 11
        ' In case of error, return ResponseCode and

' ResponseInfo.
        vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfo
    Case icResponseCompleted ' 12
        vtData = Inet1.GetChunk(1024)
    End Select
    txtresponse.Text = vtData
End Sub

There ya' go.  Straight from the VB help files.  TxtResponse is a textbox (preferably multiline with a vertical scrollbar) that displays all the returned data.  Here's a program for you.

Controls -
      Inet1   (Inet)
      txtUser (textbox)
      txtPassword (textbox)
      txtHost (textbox)
      txtResponse (textbox)
      txtDirectory (textbox)
      cmdConnect (command)
      cmdLS (command)
      cmdCD (command)
      cmdQuit (command)

Here's your program...

private sub cmdConnect_Click()

on error resume next

if txturl.text="" or txtpassword.text="" or txtuser.text="" then
      exit sub
      inet1.execute "ftp://" & txtuser.text & ":" & _ txtpass.text & "@" & txtHost.text

end sub

private sub cmdLS_Click()
      on error resume next
      inet1.execute "ftp://" & txtuser.text & ":" & _
            txtpassword.text & "@" & txthost.text,"ls"
end sub
private sub cmdCD_Click()
      on error resume next
      inet1.execute "ftp://" & txtuser.text & ":" & _
            txtpassword.text & "@" & txthost.text, "cd " & _
end sub
private sub cmdQUIT_Click()
      on error resume next
      inet1.execute "ftp://" & txtuser.text & ":" & _
            txtpassword.text & "@" & txthost.text,"bye"
end sub

Private Sub Inet1_StateChanged(ByVal State As Integer)

    Dim vtData As Variant ' Data variable.
    Select Case State

          Case icError ' 11
              vtData = Inet1.ResponseCode & ":" & _                   Inet1.ResponseInfo

      Case icResponseCompleted ' 12
              vtData = Inet1.GetChunk(1024)
    End Select

    txtResponse.Text = vtData

End Sub
All this is in the help file... Just look under the StateChanged event and at the examples.  It's pretty easy - actually, VB (some version) comes with an example of how to use the inet comtrol.

Keep at it.  

Good luck!

e_aksAuthor Commented:
Edited text of question
e_aksAuthor Commented:
yes, it is works. thanks a lot.
You're welcome! Glad to be of service!  If you want to use ftp, though, I might suggest a couple things...

First of all, the Inet control has a bunch of limitations... It's awkward, difficult to use, not really down-and-dirty, if you know what I mean.  An option would be the Winsock control.  The catch there is that you have to look at the RFC for FTP, or, like I did, just play around with it till you get the response codes down.  It's a lot safer, more secure, easier to use.

You see, every time you use the Inet control, you're sending out the username, password, and location unencrypted across the internet... :( Not too good.  Whereas if you really use FTP, you'll send it only once, at login.

The Winsock control works at a pretty basic level.  You send raw strings through it, and it gives you the raw strings which the server sends back.  You need to interpret those strings it sends back (they're all prefixed with standard 3 digit codes) and react accordingly.  It gives you utter control over the session.  

If you find the Winsock control too balky, too difficult to use (as I often do) and don't mind going third-party, there are a couple of other controls that do about the same thing, but easier, more reliably, etc.  These are freeware, or at the least, free for usage, if not royalty free

Netmanage ActiveX Control Pack - otherwise known as Internet Control Pack.  Older, harder to find, but very very good.

IPOCX, IPOCXD - these take the place of the winsock control completely, and do a pretty darn good job of it, too.  I usually use these over the winsock control, except in certain instances where binary data is passed and the control messes it up because it reads it all as strings.  But hey, no free lunches.

Anyways - you don't need to pay any attention to me. :)  I'm just talking.  

Have a nice day!

All Courses

From novice to tech pro — start learning today.