FTP 中的文件传输

发布于 2024-08-15 17:05:14 字数 2121 浏览 2 评论 0原文

我想以简单有效的方式使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-08-22 17:05:14

我相信您希望加快转账速度。

有什么有效的方法
甚至通过网络传输大文件
强度低

假设您希望使用 FTP 自己编写应用程序。

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.

生生漫 2024-08-22 17:05:14

我解决了线程问题,我将拆分功能放入一个单独的类中。我为每个输入创建新实例并将其分配给线程。现在工作正常。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文