File transfer in FTP
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 sende开发者_Python百科r, 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);
}
}
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
- Split your file
- Thread your application so that you can send multiple requests at once
- Send each file via ftp to another computer
- Recombine the file at the other end
This is assuming you wish to write the application yourself, using FTP.
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.
精彩评论