本文介绍了如何优化我的FTP下载使用的foreach()和的FtpWebRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我用的,它可以工作,但应用程序的FTP部分走约5分钟,code。

Here is the code that I am using, it will work but the ftp portion of the application is taking around 5 minutes.

该文件他们的自我不是太大,但我想,以优化应用程序,我觉得这是最好的地方开始。

The files them selves are not too big, but I would like to optimize the application and I feel like this is the best place to start.

我尝试做的是下载4特定文件。

What I try to do is download the 4 particular files.

下面是文件大小:

1 - 〜48MB2 - 〜856k3 - 〜25MB4 - 〜49MB

1 - ~48mb2 - ~856k3 - ~25mb4 - ~49mb

// BEGIN FTP
                WebClient request = new WebClient();
                request.Credentials =
                       new NetworkCredential(this.userNameRTF.Text,
                                                this.passRTF.Text);


                string[] ftpFile = new string[4];
                ftpFile[0] = "1";
                ftpFile[1] = "2";
                ftpFile[2] = "3";
                ftpFile[3] = "4";


                foreach(string s in ftpFile)
                {
                    string ftpFileName = s;


                    byte[] fileData =
                            request.DownloadData(this.ftpHost
                                                   + this.ftpPath.Text + ftpFileName);

                    FileStream file =
                        File.Create(@"\\nas03\customerftp\" + custName.Text + @"\" + ftpFileName);

                    file.Write(fileData, 0, fileData.Length);

                    file.Close();
                }

感谢您的帮助!

推荐答案

您需要告诉您的文件从,与带宽,并在那里他们将与带宽的到来。从code中的几行它似乎并不认为有任何明显的瓶颈,不是你的网络连接本身等。简单地计算出有多少数据可以下载使用的带宽。

You need to tell where your files are coming from, with which bandwith, and where they are going with which bandwith. From the few lines of code it doesn't seem that there's any obvious bottleneck, other than your internet connection itself. Simply calculate how much data can be downloaded using your bandwith.

这篇关于如何优化我的FTP下载使用的foreach()和的FtpWebRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:46