我想用简单有效的方式使用ftp传输文件。例如,如果我们想发送一个文件就意味着我们只需要把整个文件与命令一起存放起来,但是如果它是一个巨大的文件而网络强度低的话就意味着自动转换速度会降低。 即使网络实力低下,传输大文件的有效方法是什么?FTP中的文件传输
下面是一段代码,在那里我得到一些错误,请看看它。我在这里使用线程:
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);
}
}
嗨我已经使用这种方法我有一些困难,而我的应用程序线程 – karthik 2009-12-28 07:34:52
有什么困难? – torger 2009-12-28 07:44:43
其实我正在加密,压缩和分割一个文件,我把 所有这些功能放在一个线程中,而运行应用程序 与它不工作的多个文件它给出了一个例外“xx.dat”正在使用中,如果它是一个单个文件意味着它可以正常工作。这就是我最近一个月坚持的 – karthik 2009-12-28 07:55:55