日期:2014-05-17  浏览次数:20859 次

求助winform下载功能
我现在想在winform中添加下载函数,具体要求是在客户端的应用程序下载到其他ip上的文件,比如,我要下载192.168.0.101上d:\\1.xls文件,函数实现点击按钮弹出下载保存的界面,保存到本地,望各位大神能够给出能直接运行的代码,感激不尽!
winform 应用程序 下载文件

------解决方案--------------------
 WebClient 
------解决方案--------------------
 WebClient 直接down
------解决方案--------------------

 public void Download(string filePath, string ftpUri, string fileName)
        {
            FtpWebRequest reqFTP;
            try
            {
                FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);

                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpUri));
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                long cl = response.ContentLength;
                int bufferSize = 2048;
                int readCount;
                byte[] buffer = new byte[bufferSize];

                readCount = ftpStream.Read(buffer, 0, bufferSize);
                while (readCount > 0)
                {
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpS