Click here to Skip to main content
14,929,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to Connect to FTP Server, well the connection is established only once, while I want to open multiple connections and upload multiple files using threading. everything works fine Only if I upload single file. (1 by 1).


The error appears while connecting to FTP Server opening multiple connections.

C#
protected bool login()
{
    bool connected = false;
    try
    {
         IPEndPoint ip = new IPEndPoint(Dns.Resolve(ftpAddress).AddressList[0],ftpPort); //PORT = 21
         socket.Connect(ip); //The error occurs in this statement
     }
     catch (Exception ex)
     {
         Debug.Write(ex.Message);
     }
     return connected;
}

and I am getting the error "An invalid argument was supplied FTP SERVER IP"

I googled but no solution helped.

I do appreciate to understand why the error appears if I open multiple connection to ftp server?
Posted
Updated 3-Apr-11 23:54pm
v2

From the MSDN page[^] for Socket.Connect:


You can use SocketException.ErrorCode to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.


Have you tried that?
   
Comments
Abdul Rahman Hamidy 4-Apr-11 6:14am
   
thanks, Socket Error Code is 10022, I am trying to figure out what that error code means, If you have information please let me know.
Henry Minute 4-Apr-11 6:17am
   
Well the quote I gave tells you how to find out.

In case you are having difficulty here (http://msdn.microsoft.com/en-us/library/ms740668%28v=vs.85%29.aspx) is the page it refers to.
Abdul Rahman Hamidy 4-Apr-11 6:25am
   
thanks, the link does not provide enough information as it provide
"Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket—for instance, calling accept on a socket that is not listening."
Henry Minute 4-Apr-11 6:34am
   
I think the clue here might be the last sentence. If you are creating multiple threads then the socket might still be busy processing the first one when the second one tries to connect and so on.

If it were me I would start by investigating (reading thoroughly) the REMARKS section of the page I linked to.
Abdul Rahman Hamidy 4-Apr-11 6:40am
   
well, that Idea i got when debugging the code a few min ago, then I tried to find out if there is any properties to let me know the status, I find only Connected but no such properties which let me know the listen status, I would appreciate to know any ideas.
You can only connect once using the same socket. You appear to be using an instance variable 'socket' and therefore when you call login the second time socket is already connected, so trying to connect again will fail.

To open multiple connections you need to create multiple sockets.
   
Comments
Abdul Rahman Hamidy 4-Apr-11 6:47am
   
well I am using different Objects, as f.login() and another f1.login(),
BobJanova 4-Apr-11 9:07am
   
Does each one create a new instance of socket? If socket is a static field then that will still be the problem.
Abdul Rahman Hamidy 5-Apr-11 0:11am
   
sure its not defined as static, Socket variable is private as Socket socket=....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900