Click here to Skip to main content
15,039,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i want to send 2 files to FTP Server in same time, concurrent
How can i do it?

My code have error:
---------------------------
Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.


C#
namespace FTP
{
    public partial class Form1 : Form
    {
       string MyServerIP;
        string MyUserID;
        string MyPassword;
        string MyFilename;

        private Thread Threadx1 = null;
        private Thread Threadx2 = null;

        public Form1()
        {
            InitializeComponent();

            Threadx1 = new Thread(new ThreadStart(Thread1));
            Threadx1.IsBackground = true;

            Threadx2 = new Thread(new ThreadStart(Thread2));
            Threadx2.IsBackground = true;
        }

        public void Thread1()
        {
            MyServerIP = "127.0.0.1";
            MyUserID = "user1";
            MyPassword = "user1";
            MyFilename = "C:\\a.txt";
            Upload(MyServerIP,MyUserID,MyPassword,MyFilename);
        }

        private void Thread2()
        {
            MyServerIP = "127.0.0.1";
            MyUserID = "user2";
            MyPassword = "user2";
            MyFilename = "C:\\a.txt";
            Upload(MyServerIP,MyUserID,MyPassword,MyFilename);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Threadx1.Start();
            Threadx2.Start();
        }

    }
}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 30-Apr-12 8:00am
v2

1 solution

I't difficult to be sure - but try some simple debugging:
0) Look at the exception detail - is there any clue in the Inner Exception? Is it always one thread, or the other?
1) Remove Thread2.Start and see if it works. If it doesn't then it isn't a problem with threading.
2) If it does work, the try sending a different file on each thread: it could be that the attempt to read and / or write the same file on two threads is the problem at one end or the other.
   

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