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

C#实现ftp下载支持断点续传
前几天做个ftp下载小程序单位用,但是发现有时候文件下载不完整,我查了老半天才发现时因为网络延迟导致,解决方法是加个断线续传,爱我去,一开始我以为挺简单,做了两天参照网上的代码就是不行,才请各位老师们指点指点
if (a.ToString() != readCount.ToString())//断点续传
                {
                    Uri urii=new Uri("ftp://192.168.1.123:21");
                    FileInfo fileInfo = new FileInfo("E:\\报价\\巴比来定制产品.rar");
                    long locSize = fileInfo.Length;
                    RestartDownloadFromServer("巴比来定制产品.rar", urii, locSize);
                    CloseSocketConnect();
                    Socket soketData = CreateDataSocket();
                    Byte[] cmdType = GB2312.GetBytes(("TYPE I \r\n"));
                    socketControl.Send(cmdType, cmdType.Length, 0);

                    MessageBox.Show("开始断点续传");
                    FileStream output = new
                    FileStream("E:\\报价\\" + "巴比来定制产品.rar", FileMode.Append, FileAccess.Write);
                    Byte[] cmdPASV = GB2312.GetBytes(("PASV \r\n").ToCharArray());
                    socketControl.Send(cmdPASV, cmdPASV.Length, 0);
                    //获取本地文长度
                    FileInfo fileInfo = new FileInfo("E:\\报价\\巴比来定制产品.rar");
                    long locSize = fileInfo.Length;