Solved

Inet

Posted on 1998-05-09
4
510 Views
Last Modified: 2013-11-13
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.
0
Comment
Question by:e_aks
  • 2
  • 2
4 Comments
 

Author Comment

by:e_aks
ID: 1444944
Edited text of question
0
 
LVL 1

Accepted Solution

by:
johnny_5 earned 20 total points
ID: 1444945
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 - ftp.asdf.com
            (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:
      ftp://joe:123@ftp.asdf.com

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:  ftp://joe:123@www.asdf.com

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)
            RemotePort=21
      txtUser (textbox)
      txtPassword (textbox)
      txtHost (textbox)
      txtResponse (textbox)
            multiline=true
            scrollbars=Vertical
      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
else
      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 " & _
            txtDirectory.text
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!




      
0
 

Author Comment

by:e_aks
ID: 1444946
yes, it is works. thanks a lot.
0
 
LVL 1

Expert Comment

by:johnny_5
ID: 1444947
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!


0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now