?
Solved

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

Posted on 2003-02-22
12
Medium Priority
?
802 Views
Last Modified: 2013-11-13
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
Comment
Question by:mn8102429
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +4
12 Comments
 

Expert Comment

by:kevmeist
ID: 7999313
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
 

Expert Comment

by:amIT
ID: 7999555
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
 

Expert Comment

by:pkmnfrk
ID: 7999669
What protocol are you using? TCP or UDP?
0
Technology Partners: 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!

 

Author Comment

by:mn8102429
ID: 8002537
->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
 

Expert Comment

by:kevmeist
ID: 8002696
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
 

Expert Comment

by:kevmeist
ID: 8002716
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
 

Expert Comment

by:kevmeist
ID: 8002730
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
 

Expert Comment

by:amIT
ID: 8003092
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
 

Author Comment

by:mn8102429
ID: 8015309
Thanks everybody! I will consider all your valuable suggestions and get back to you after testing them.
0
 

Expert Comment

by:CleanupPing
ID: 8901262
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 8964145
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9104025
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

765 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