Results 1 to 5 of 5

Thread: Newbie with VB6 winsock

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    2

    Newbie with VB6 winsock

    I'm asking for help about the winsock control to do a ftp client...
    Here is my code:

    VB Code:
    1. Private Sub btnConnect_Click()
    2.  
    3. Dim buffer As String
    4. Winsock1.RemoteHost = "ftpperso.free.fr"
    5. Winsock1.RemotePort = 21
    6.  
    7. If Winsock1.Connect Then
    8. MsgBox ("On est pas connecté")
    9. End If
    10.  
    11.  
    12. Winsock1.SendData ("USER *****")
    13. Winsock1.Accept (buffer)
    14.  
    15. txtCmdRec.Text = buffer
    16.  
    17. End Sub

    I'm sure that my script doesn't work but how learn without mistake ^^

    Thx for your help

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Newbie with VB6 winsock

    try checking for the connect in the winsock connect sub, also check the state

    Private Sub Winsock1_Connect()
    If Winsock1.State = sckConnected Then
    'connected add code
    Else
    'add other code error code, etc
    End If

    End Sub
    When your dreams come true.
    On error resume pulling hair out.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Newbie with VB6 winsock

    Quote Originally Posted by Calimorphos
    I'm sure that my script doesn't work but how learn without mistake ^^

    Thx for your help
    Welcome to the forums.

    What specific problems are you having? That was not stated in your post.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    2

    Re: Newbie with VB6 winsock

    That's right, my question was not well set. Exactly i have a problem with the line 7:

    VB Code:
    1. winsock1.connect

    compilation error
    unknown type (*unknown shouldn't be the righr word but I translate FR/EN sorry ^^)

    Thx for your answers

  5. #5
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Newbie with VB6 winsock

    hi,

    You need to check if connected by checking the winsock state.

    ok I left some code below . it will need some work but gives you a basic idea. anyway hope it may help you a little get started.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Winsock1.RemoteHost = "dream"
    3.     Winsock1.Protocol = sckTCPProtocol
    4.     Winsock1.RemotePort = 21
    5.     Winsock1.Connect
    6. End Sub
    7.  
    8. Private Sub Winsock1_Connect()
    9.     ' check for a connection. also see StateConstants for more consts
    10.     If Winsock1.State = sckConnected Then
    11.         MsgBox "Connected"
    12.     Else
    13.         MsgBox "Not connected"
    14.     End If
    15.    
    16. End Sub
    17.  
    18. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    19. Dim sdata As String, e_pos As Integer, sCmd As String
    20.  
    21.     DoEvents
    22.     Winsock1.GetData sdata, , bytesTotal
    23.     e_pos = InStr(1, sdata, Chr(32), vbBinaryCompare)
    24.    
    25.     If e_pos <> 0 Then sCmd = Trim(Left(sdata, e_pos)) 'Get ftp commands
    26.  
    27.     Select Case sCmd
    28.         Case 220 'Welcome message
    29.             MsgBox Right(sdata, Len(sdata) - Len(sCmd))
    30.             'send username
    31.             Winsock1.SendData "USER ben" & vbCrLf
    32.         Case 331
    33.             'send password
    34.             Winsock1.SendData "PASS ben" & vbCrLf
    35.         Case 530
    36.             'incorrect login or password
    37.             MsgBox Right(sdata, Len(sdata) - Len(sCmd))
    38.     End Select
    39.    
    40. End Sub
    Last edited by dreamvb; Aug 26th, 2005 at 03:04 PM.
    When your dreams come true.
    On error resume pulling hair out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width