|
-
Aug 26th, 2005, 12:29 PM
#1
Thread Starter
New Member
Newbie with VB6 winsock
I'm asking for help about the winsock control to do a ftp client...
Here is my code:
VB Code:
Private Sub btnConnect_Click()
Dim buffer As String
Winsock1.RemoteHost = "ftpperso.free.fr"
Winsock1.RemotePort = 21
If Winsock1.Connect Then
MsgBox ("On est pas connecté")
End If
Winsock1.SendData ("USER *****")
Winsock1.Accept (buffer)
txtCmdRec.Text = buffer
End Sub
I'm sure that my script doesn't work but how learn without mistake ^^
Thx for your help
-
Aug 26th, 2005, 12:46 PM
#2
Hyperactive Member
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.
-
Aug 26th, 2005, 01:26 PM
#3
Re: Newbie with VB6 winsock
 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.
-
Aug 26th, 2005, 01:56 PM
#4
Thread Starter
New Member
Re: Newbie with VB6 winsock
That's right, my question was not well set. Exactly i have a problem with the line 7:
compilation error
unknown type (*unknown shouldn't be the righr word but I translate FR/EN sorry ^^)
Thx for your answers
-
Aug 26th, 2005, 02:45 PM
#5
Hyperactive Member
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:
Private Sub Command1_Click()
Winsock1.RemoteHost = "dream"
Winsock1.Protocol = sckTCPProtocol
Winsock1.RemotePort = 21
Winsock1.Connect
End Sub
Private Sub Winsock1_Connect()
' check for a connection. also see StateConstants for more consts
If Winsock1.State = sckConnected Then
MsgBox "Connected"
Else
MsgBox "Not connected"
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sdata As String, e_pos As Integer, sCmd As String
DoEvents
Winsock1.GetData sdata, , bytesTotal
e_pos = InStr(1, sdata, Chr(32), vbBinaryCompare)
If e_pos <> 0 Then sCmd = Trim(Left(sdata, e_pos)) 'Get ftp commands
Select Case sCmd
Case 220 'Welcome message
MsgBox Right(sdata, Len(sdata) - Len(sCmd))
'send username
Winsock1.SendData "USER ben" & vbCrLf
Case 331
'send password
Winsock1.SendData "PASS ben" & vbCrLf
Case 530
'incorrect login or password
MsgBox Right(sdata, Len(sdata) - Len(sCmd))
End Select
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|