• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • Last Modified:

Run-time error '40006', Wrong protocol or connection state...

Hi.

I'm trying to construct an FTP client which works "in the background", as it logs in, retrieves a certain HTML file, changes it contents and puts it back. Any way, I have put the wsCommand.SendData in the Form_Load() but after running it complains with the message "Run-time error '40006', wrong protocol or connection state for the requested transaction or request". However, same set of commands work superbly when I test them from my "console" which is simply a TextBox control, and which submits the commands when I press Enter.

So what is your suggestion? Quick answers highly appreciated.
0
mn8102429
Asked:
mn8102429
  • 4
  • 2
  • 2
  • +4
1 Solution
 
kevmeistCommented:
Sounds like you are try to send without the connection being valid.

See http://support.microsoft.com/default.aspx?scid=KB;en-us;q183987

for more data.

Kevin
0
 
amITCommented:
Can yuo tell exactly, after which command you get the error ?
Probably you need to insert this "do while" in your code this code:

Winsock1.Connect FTP_HOST, "21"
Do While Winsock1.State <> sckConnected
DoEvents
Winsock1.senddata "user guest"
....

hth,
amit
0
 
pkmnfrkCommented:
What protocol are you using? TCP or UDP?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mn8102429Author Commented:
->pkmnfrk.
I'm using TCP but I've tried UDP as well. UDP does not result in an error but it makes the server at the other end to disconnect, if i remember right. I have also tried NNTP with both TCP and UDP. The outcome was the same.

->amIT.
Here we go:
  Private Sub Form_Load()
  ...
  'works. the server replies with a welcome text
  'and asks for authentication:
  wsCommand.Connect "myserver", 21
  'fails:
  wsCommand.SendData "USER myusername" & vbCrLf
  ...
  End Sub

->kevmeist.
Quite improbable(see above). But I'll check it out.

Thanks everybody
0
 
kevmeistCommented:
There are also comments out on the web about deficiencies in the MS provided Winsock control and some replacements also. Try http://www.killervb.com/WinsockLib.aspx

Kevin
0
 
kevmeistCommented:
In the code snippet and text that you posted...you say that the connect works and asks for authentication but you don't mention or show code that provides that. The socket connection is not valid, I believe, until you authenticate. Have you tried to do this with an anonymous connection so that it doesn't need authenticating ?

Kevin
0
 
kevmeistCommented:
There is also sample code for an FTP client at:

http://www.planet-source-code.com/xq/ASP/txtCodeId.1783/lngWId.1/qx/vb/scripts/ShowCode.htm

You may want to look there and see if you can find a solution. I have to believe that really don't have the connection that you think you do.

Kevin
0
 
amITCommented:
Hi,
1. Use TCP.
2. Try this code:
 Private Sub Form_Load()
 wsCommand.Connect "myserver", 21
 Do While Winsock1.State <> sckConnected
 DoEvents
 wsCommand.SendData "USER myusername" & vbCrLf
 
This should work.

hth,
amit
0
 
mn8102429Author Commented:
Thanks everybody! I will consider all your valuable suggestions and get back to you after testing them.
0
 
CleanupPingCommented:
mn8102429:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
mn8102429, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 
YensidModCommented:
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now