views:

77

answers:

2

I want to transfer files using ftp in a simple and effective manner. For example, if we want to send a file means we just put the entire file with commands, but if it is a huge file and the network strength is low means automatically the transferspeed will be reduced. What will be the effective method to transfer a huge file even the network strength is low?

Below is the piece of code where i get some error,please have a look at it.i employed threading here:

public partial class Form1 : Form
{
    ArrayList AscendingList = new ArrayList();
    ListViewItem Litem = null;
    Thread MyThread = null;
    ThreadStart Starter = null;

    public Form1()
    {
        InitializeComponent();
    }

    private void btn_split_Click(object sender, EventArgs e)
    {
        foreach (ListViewItem litem in listView1.Items)
        {
            Starter = delegate { SplitFile(litem.Text,litem.SubItems[1].Text,int.Parse(litem.SubItems[2].Text)); };
            MyThread = new Thread(Starter);
            MyThread.IsBackground = true;
            MyThread.Start();
        }
    }
    public void SplitFile(string inputFile, string outputPrefix, int chunkSize)
    {
        int pointr = 0;
        byte[] buffer = new byte[chunkSize];

        using (FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.None))
        {
            int index = 0;
            pointr = fs.Read(buffer, 0, buffer.Length);
            while (pointr != 0)
            {
                using (FileStream fso = new FileStream(outputPrefix + "\\" + index + ".log", FileMode.Create))
                {
                    AscendingList.Add(fso.Name);
                    fso.Write(buffer, 0, pointr);
                    pointr = fs.Read(buffer, 0, buffer.Length);
                }
                index++;
            }
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Litem = new ListViewItem();
        Litem.Text = "E:\\butterfly.mpg";
        Litem.SubItems.Add("H:\\karthik");
        Litem.SubItems.Add("102400");
        listView1.Items.Add(Litem);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Litem = new ListViewItem();
        Litem.Text = "E:\\karthik.mpeg";
        Litem.SubItems.Add("H:\\karthik\\karthik");
        Litem.SubItems.Add("102400");
        listView1.Items.Add(Litem);
    }
}
+1  A: 

I believe you want to accelerate your transfers.

what will be the effective method to transfer a huge file even the network strngth is low

This is assuming you wish to write the application yourself, using FTP.

Nazarius Kappertaal
hi i already used this method i have some difficulty while threading my application
karthik
What is the difficulty?
Nazarius Kappertaal
Actually i am encrypting,compressing and splitting a file ,i put all these functionalities in a thread,while running the applicationwith multiples files it doesnt work it gives an exception "xx.dat" is in use.if it is a single file means it works fine.thats wherei got stuck up for the last one month
karthik
Encrypt/compress first, then split, then thread.
Nazarius Kappertaal
if my filesize is 350mb and that one is also a video file then what will happpen in that case? if i try splitting a video file of 350mbwithout using thread means the ui will get hanged
karthik
hi naz please look at the code and give me some suggestions
karthik
A: 

I RESOLVED THE THREAD ISSUE,I PUT THE SPLITTING FUNCTIONALITY INTO A SEPARATE CLASS .I CREATE NEW INSTANCE FOR EVRY INPUT AND ASSIGN IT TO A THREAD.IT WORKS FINE NOW.

karthik