Welcome to the Xceed Community | Help
Community Search  

Is Xceed FTP .NET threadsafe?

Sort Posts: Previous Next
  •  11-29-2008, 10:58 AM Post no. 17270

    Is Xceed FTP .NET threadsafe?

    Hi all,

    we have an application which generates approx. 20 zipfiles which are in turn sent to an FTP server. This is done in a serial manner, so first the 1st file is generated and then sent to the desired FTP server, then the 2nd and so on. Because the target FTP servers are all different in URL or subdirectory it isn't possible to send them in batch.

    To speed up things we changed the internal structure of the application so that it uses a threadpool and we create a new worker thread for each file to generate/FTP. The pool is now set to max. 3 threads.

    When I run the app. the generating of the files is ok but it goed haywire when the threads start to implement FTP. When two threads start to FTP at about the same time they seem to hang first. Then after ± 1 minute one of the threads get an FTP connect exception (code 426) and at that same time the other thread gets it's connection, uploads the file and is finished.

    It has the signature of a deadlock where one thread ultimately is the victim. When I set the max. threads of the pool to 1 everything is ok.

    Is it possible to use Xceed in this manner in multiple threads? Or do the threads interfere each other at the FTP stage because Xceed isn't threadsafe? 

    TIA,

    Friso Wiskerke

    Filed under:
  •  12-02-2008, 4:07 PM Post no. 17310 in reply to 17270

    Re: Is Xceed FTP .NET threadsafe?

    Are you using the same Ftp instance on each thread?  If so, this will not work.  You need to initialize a new FtpClient object for every thread.
    André
    Software Developer and Tech Support
    Xceed Software Inc.
  •  12-03-2008, 11:05 AM Post no. 17328 in reply to 17310

    Re: Is Xceed FTP .NET threadsafe?

    André,

    each thread has it's own instance of the XCeed FTP object.

  •  12-05-2008, 12:38 PM Post no. 17370 in reply to 17328

    Re: Is Xceed FTP .NET threadsafe?

    First, we do not reproduce this on our side.  However, could you provide the code you're using, to make sure we are doing things the same way?


    André
    Software Developer and Tech Support
    Xceed Software Inc.
  •  12-08-2008, 10:40 AM Post no. 17385 in reply to 17370

    Re: Is Xceed FTP .NET threadsafe?

    André,

    can you provide us the code you have used to try to reproduce the multithreading issue? maybe it can help us in the right direction....

  •  12-08-2008, 10:42 AM Post no. 17386 in reply to 17370

    Re: Is Xceed FTP .NET threadsafe?

    Hello Andre,

    We use this code:

    == Program.cs ==
    class Program
    {
        static void Main(string[] args)
        {
           
    ThreadPool.SetMaxThreads(2, 2);

            for (int i = 1; i < 7; i++ )
            {
                WorkerThread wt = new WorkerThread();
               
    ThreadPool.QueueUserWorkItem(new WaitCallback(wt.TransportViaFTP), string.Format("d:\\file00{0}.rar", i));
            }

            Console.ReadLine();
       
    }
    }

    == WorkerThread.cs ==
    internal class WorkerThread
    {
       
    internal void TransportViaFTP( object fileName )
       
    {
           
    try
           
    {
                Xceed.Ftp.Licenser.LicenseKey = "our key";
                Xceed.Ftp.
    FtpClient oFTP = new Xceed.Ftp.FtpClient();

                oFTP.Connect(
    "ftp server");
                oFTP.Login(
    "login", "password");

                oFTP.PassiveTransfer = true;
                oFTP.Timeout = 10;
                oFTP.KeepAliveInterval = 10;

                oFTP.ChangeCurrentFolder("/Test");

                oFTP.SendFile(fileName.ToString());
            }
           
    catch (Exception ex)
            {
               
    string message = ex.Message;
            }
        }
    }

    The exception is "The FTP command execution timed-out."

  •  12-11-2008, 10:36 AM Post no. 17465 in reply to 17386

    Re: Is Xceed FTP .NET threadsafe?

    Ok, after further investigation, the problem is that we are also using the ThreadPool internally to send command to the server, and limiting it to only 2-3 threads concurrently prevents the call to SendFile, which results into the exception.

    So you basically have two choices.  Either do not limit the number of threads on the ThreadPool, or create your own 2-3 threads, and manage yourself the ftp transfer as each thread becomes available.

    Note that we have a new version coming out in February which we have modified in term of thread and asynchronous processing, and we have tested this with the beta version, and it works fine.  So you will be able to revert your code back when this version is released.  Note however that this will require to be a vanguard support subscriber to be able to get it free, else you will need to  buy an upgrade.  It will be version 4.0.  We can send the beta version to vanguard support subscribers.


    André
    Software Developer and Tech Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.