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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您希望加快转账速度。
可以发送多个请求
一次
另一台计算机
end
假设您希望使用 FTP 自己编写应用程序。
I believe you want to accelerate your transfers.
can send multiple requests at
once
another computer
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.