Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.2k views
in .NET FTP by (360 points)
hi experts,

I have hit upon a problem which I'm not sure is my usage or a bug in the dll. I'm using the free version of the .net client ftp up agains a filezilla server.

I have mad a small test program that illustrates the problem. Basically 2 threads, one uploading and one getting fileInfos, each with its own FtpConnection. And still there is an exception thrown.

I have only seen the problem when using passive connection, but I'm not sure if that is conclusive.

Wouldn't the ftpConnection live completely seperately and not be able to influence other ftpConnections in other threads?


System.Net.Sockets.SocketException was unhandled
Message=Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:1911
Source=System
ErrorCode=10048
NativeErrorCode=10048
StackTrace:
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at EnterpriseDT.Net.StandardSocket.Connect(EndPoint remoteEP)
at EnterpriseDT.Net.Ftp.FTPControlSocket.NewPassiveDataSocket(String ipAddress, Int32 port)
at EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocketPASV()
at EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocket(FTPConnectMode connectMode)
at EnterpriseDT.Net.Ftp.FTPClient.Dir(String dirname, Boolean full)
at EnterpriseDT.Net.Ftp.FTPClient.DirDetails(String dirname)
at EnterpriseDT.Net.Ftp.FTPConnection.GetFileInfos(String directory)
at EnterpriseDT.Net.Ftp.FTPConnection.GetFileInfos()
at EDtFtpTestProject.Program.<>c__DisplayClass6.<startInfos>b__5() in c:\documents and settings\kilbe\my documents\visual studio 2010\Projects\EDtFtpTestProject\EDtFtpTestProject\Program.cs:line 86
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

11 Answers

0 votes
by (162k points)
Set SynchronizePassiveConnections = true

Port numbers can't be shared between processes.
0 votes
by (360 points)
Hi again,

Thank you for the suggestion, but it gives the same result. I set the SynchronizePassiveConnections = true just before the connect() invocation.

You write that port numbers cannot be shared between processes, but my program is working in threads. Are you referring to a process that has been running earlier that might have had some influence on the currently executing program?

It seems that it matters if the computer is freshly booted then I can run the program once with no crashed. And if I launch it again immediately, then it crashes very soon in the loop. Letting the computer rest a few minutes before trying again can help it run to the end with no exceptions. Not sure how this can be? Is it a misuse of the library from my side?

Br
Kim Bendtsen
0 votes
by (162k points)
Port numbers can't be shared between threads either.
0 votes
by (360 points)
As far as I know, I'm not sharing ports betwen process.

Each thread is asking for a new FTPConnection instance object. Then each thread uses seperate connection objects to send and receive data with. This leads to the exception as described previosly.

Is there anything wrong with this progres?

Br
Kim Bendtsen
0 votes
by (162k points)
Please post the log file so we can see what's happening (Debug level).

For some reason you are getting a clash on 127.0.0.1:1911 (no doubt diff port each time there's a problem).

In particular I'd like to see the server's response to the PASV command.
0 votes
by (360 points)
Hi again,

Here is a full log from when the program is run. It crashes on the first iteration. The thing is that it makes a difference if the program has been run before. So something seems to be hanging.
The target .net framework is 2.0. (Just tested with targit framework set to 4.0 and it gives the same result).

DEBUG [FTPConnection] 30 aug 2010 10:41:17.025 : Set LocalDirectory='C:\Documents and Settings\kilbe\my documents\visual studio 2010\Projects\EDtFtpTestProject\EDtFtpTestProject\bin\Debug'
DEBUG [FTPConnection] 30 aug 2010 10:41:17.025 : Set LocalDirectory='C:\Documents and Settings\kilbe\my documents\visual studio 2010\Projects\EDtFtpTestProject\EDtFtpTestProject\bin\Debug'
DEBUG [FTPClient] 30 aug 2010 10:41:17.025 : Connecting to 127.0.0.1:21
DEBUG [FTPClient] 30 aug 2010 10:41:17.025 : Connecting to 127.0.0.1:21
DEBUG [HostNameResolver] 30 aug 2010 10:41:17.072 : Resolving 127.0.0.1
DEBUG [HostNameResolver] 30 aug 2010 10:41:17.072 : Resolving 127.0.0.1
DEBUG [HostNameResolver] 30 aug 2010 10:41:17.072 : 127.0.0.1 resolved to 127.0.0.1
DEBUG [HostNameResolver] 30 aug 2010 10:41:17.072 : 127.0.0.1 resolved to 127.0.0.1
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : Setting socket timeout=60000
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : Setting socket timeout=60000
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : Command encoding=System.Text.ASCIIEncoding
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : Command encoding=System.Text.ASCIIEncoding
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 220-FileZilla Server version 0.9.36 beta
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 220-FileZilla Server version 0.9.36 beta
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 220-written by Tim Kosse (Tim.Kosse@gmx.de)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 220-written by Tim Kosse (Tim.Kosse@gmx.de)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 220 Please visit http://sourceforge.net/projects/filezilla/
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 220 Please visit http://sourceforge.net/projects/filezilla/
DEBUG [FTPConnection] 30 aug 2010 10:41:17.072 : Connected to 127.0.0.1 (instance=0)
DEBUG [FTPConnection] 30 aug 2010 10:41:17.072 : Connected to 127.0.0.1 (instance=1)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> USER vobServer
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> USER vobServer
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 331 Password required for vobserver
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 331 Password required for vobserver
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> PASS ********
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> PASS ********
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 230 Logged on
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 230 Logged on
DEBUG [FTPConnection] 30 aug 2010 10:41:17.072 : Successfully logged in
DEBUG [FTPConnection] 30 aug 2010 10:41:17.072 : Successfully logged in
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> TYPE I
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> TYPE I
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 200 Type set to I
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 200 Type set to I
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> PWD
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> PWD
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 257 "/" is current directory.
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 257 "/" is current directory.
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> CWD /log/can
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> CWD /log/can
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 250 CWD successful. "/log/can" is current directory.
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> PWD
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 257 "/log/can" is current directory.
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 250 CWD successful. "/log/can" is current directory.
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : ---> PWD
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.072 : 257 "/log/can" is current directory.
DEBUG [FTPConnection] 30 aug 2010 10:41:17.088 : UploadFile(c:\tmp\vobFtpServer\log\can\gnd-ascylog000142.elog,gnd-ascylog000143.elog,False)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : ---> SYST
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : 215 UNIX emulated by FileZilla
DEBUG [FTPFileFactory] 30 aug 2010 10:41:17.088 : Selected UNIX parser
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : ---> PWD
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : 257 "/log/can" is current directory.
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : ---> PASV
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : 227 Entering Passive Mode (127,0,0,1,6,121)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : Server supplied address=127.0.0.1
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : Server supplied port=1657
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : autoPassiveIPSubstitution=True
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : remoteAddr=127.0.0.1
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : Substituting server supplied IP (127.0.0.1) with remote host IP (127.0.0.1)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:17.088 : NewPassiveDataSocket(127.0.0.1,1657)
ERROR [FTPControlSocket] 30 aug 2010 10:41:17.088 : Failed to create connecting socket
ERROR [FTPControlSocket] 30 aug 2010 10:41:17.088 : System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:1657
ERROR [FTPControlSocket] 30 aug 2010 10:41:17.088 : at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
ERROR [FTPControlSocket] 30 aug 2010 10:41:17.088 : at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
ERROR [FTPControlSocket] 30 aug 2010 10:41:17.088 : at EnterpriseDT.Net.StandardSocket.Connect(EndPoint remoteEP)
ERROR [FTPControlSocket] 30 aug 2010 10:41:17.088 : at EnterpriseDT.Net.Ftp.FTPControlSocket.NewPassiveDataSocket(String ipAddress, Int32 port)
DEBUG [FTPControlSocket] 30 aug 2010 10:41:20.228 : ---> PASV
0 votes
by (162k points)
It looks to me like the Filezilla server is sending the same PASV command to each instance. Is that what is happening?
0 votes
by (360 points)
Hi again,

I'm not sure how to look for this..

Any chance you could take the source code supplied and run it against one of your ftp servers?

It needs to run 2 or 3 times in a row on my pc to course the exception.

Br
Kim
0 votes
by (360 points)
While looking for replies I noticed that there is no source code.. Weird, I so sure I attached it on the first email.. Anyway, here it is again.

The structure of the program is made to resemble the original program where I stubled upon the problem in.

using System;
using System.Collections.Generic;

using System.Text;
using EnterpriseDT.Net.Ftp;
using System.Threading;
using System.Timers;
using System.Diagnostics;

namespace EDtFtpTestProject
{
    class Program
    {
        private string user = "woo";
        private string password = "woo";
        private string ftpServer = "127.0.0.1";
        private FTPConnectMode connectMode = FTPConnectMode.PASV;
        private int repetions = 1000;


        private FTPConnection getFtpConnection()
        {

            FTPConnection con = new FTPConnection();
            FTPConnection.LogFile = "logs";
            FTPConnection.LogLevel = EnterpriseDT.Util.Debug.LogLevel.Debug;

            con.ServerAddress = ftpServer;
            con.ServerPort = 21;
            con.UserName = user;
            con.Password = password;
            con.Timeout = 60000; // one minute
            con.ConnectMode = connectMode;
            con.SynchronizePassiveConnections = true;
            con.Connect();
            
            return con;

        }
    

        public void startUpload(object sender, ElapsedEventArgs args)
        {
            
            Thread tUpload = new Thread(delegate()
            {

                FTPConnection conUpload = getFtpConnection();
                conUpload.ChangeWorkingDirectory("/log/can");
                
                for (int i = 0; i < repetions; i++)
                {
                    Console.WriteLine("Uploading file: {0}", i);               
                    conUpload.UploadFile(@"c:\tmp\vobFtpServer\log\can\gnd.elog", "gnd.elog");
                }

            });
            tUpload.Start();
        }
   
        public void startInfos(object sender, ElapsedEventArgs args)
        {
            Thread tDir = new Thread(delegate()
            {
                FTPConnection conDir = getFtpConnection();

                conDir.ChangeWorkingDirectory("/log/can");
                
                for (int i = 0; i < repetions; i++)
                {
                    Console.WriteLine("List Dir: {0}", i);
                    conDir.GetFileInfos();
                    
                }
            });
            tDir.Start();
        }

        static void Main(string[] args)
        {
            //started this way to resemble the structure of my program.
            Program p = new Program();
            System.Timers.Timer t1 = new System.Timers.Timer();
            t1.Interval = 1000;
            t1.Elapsed += new ElapsedEventHandler(p.startUpload);
            
            System.Timers.Timer t2 = new System.Timers.Timer();
            t2.Interval = 1000;
            t2.Elapsed += new ElapsedEventHandler(p.startInfos);

            t1.Start();
            
            t2.Start();

            Thread.Sleep(1500); // just make sure we don't start any more. 
            t1.Enabled = false;
            
            t2.Enabled = false;

            Thread.Sleep(9000);
            
            Console.WriteLine("Done");
        }
    }
}
0 votes
by (360 points)
Did you try to run it though a compiler?

Categories

...