Exemple #1
0
 private void btnPause_Click(object sender, EventArgs e)
 {
     //if (btnPause.Text == "Exit")
     //{
     //    sFtp.StopDownload();
     //    //sFtp.Disconnect();
     //    //sFtp = null;
     //    this.Dispose();
     //}
     //else
     if (btnPause.Text == "Pause")
     {
         if (type == "FTP")
         {
             Ftp.UploadDownloadPause = "Y";
         }
         else
         {
             sFtp.StopDownload();
             sFtp.UploadDownloadPause = "Y";
         }
         btnPause.Text    = "Start";
         dgvList.ReadOnly = false;
     }
     else
     {
         if (type == "FTP")
         {
             Ftp.UploadDownloadPause = "N";
         }
         else
         {
             sFtp = null;
             sFtp = new SFTP.SFTP(sitename, siteip, userid, pwd, port, renamefile, "Override");
             sFtp.Connect();
             sFtp.ResumeDownload();
             sFtp.UploadDownloadPause = "N";
         }
         btnPause.Text = "Pause";
         callbyPause   = true;
         btnDownload_Click(null, null);
     }
 }
Exemple #2
0
        private void t_prepare_Tick(object sender, EventArgs e)
        {
            try
            {
                t_prepare.Enabled = false;
                this.Cursor       = Cursors.AppStarting;

                clickbychkall = true;
                //在读取文件的时候读取空文件夹,因为读取文件列表的时候空文件夹不在文件列表中,会造成空文件夹上传丢失

                lblStatus.Text = "Getting site profile...";
                Application.DoEvents();
                using (DataTable dt = DB.GetSiteProfileDetail(sitename))
                {
                    type       = dt.Rows[0]["Type"].ToString();
                    siteip     = dt.Rows[0]["SiteIP"].ToString();
                    userid     = dt.Rows[0]["UserID"].ToString();
                    pwd        = Security.Decrypt(dt.Rows[0]["Password"].ToString());
                    renamefile = dt.Rows[0]["RenameFile"].ToString();
                    port       = dt.Rows[0]["Port"].ToString();
                }

                lblStatus.Text = "Creating " + type + " instance...";
                if (type == "FTP")
                {
                    Ftp = new FTP.FTP(sitename, siteip, userid, pwd, port, renamefile, "Override");
                }
                else
                {
                    sFtp = new SFTP.SFTP(sitename, siteip, userid, pwd, port, renamefile, "Override");
                    sFtp.Connect();
                }
                Thread.Sleep(300);
                Application.DoEvents();

                if (dtChoosedList == null)
                {
                    #region Continue upload
                    btnUpload.Text  = "Continue upload";
                    btnUpload.Width = 129;
                    btnUpload.Left  = 702;
                    btnPause.Left   = 640;
                    lblStatus.Text  = "Getting breakpoint resume files list...";
                    Thread.Sleep(300);
                    Application.DoEvents();

                    dtAllResumeFiles = DB.GetUploadBreakpointResumeFileList(sitename);
                    if (dtAllResumeFiles.Rows.Count > 0)
                    {
                        lblFtpPath.Text = dtAllResumeFiles.Rows[0]["FtpPath"].ToString();
                    }
                    foreach (DataRow dr in dtAllResumeFiles.Rows)
                    {
                        //取得文件列表后,检索服务器上文件上传载情况。
                        if (dr["Type"].ToString() == "File Folder")
                        {
                            bool bChkResult = true;
                            if (type == "FTP")
                            {
                                bChkResult = Ftp.CheckFileExist(dr["FtpFullFilePath"].ToString(), dr["FileNameWithoutPath"].ToString());
                            }
                            else
                            {
                                bChkResult = sFtp.CheckFileExist(dr["FtpFullFilePath"].ToString(), dr["FileNameWithoutPath"].ToString());
                            }
                            if (bChkResult == false)
                            {
                                DB.SaveUploadlist(sitename, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), lblFtpPath.Text, dr["Type"].ToString(), dr["FileSize"].ToString(), dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["ModifyDate"].ToString());
                                dgvList.Rows.Add(res.wait, false, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(), "<!>Can't find the folder, need recreat",
                                                 dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["Type"].ToString(), dr["ModifyDate"].ToString());
                            }
                        }
                        else
                        {
                            string filename = null;
                            if (renamefile == "Y")
                            {
                                filename = dr["FtpFullFilePath"].ToString() + ".tmp";
                            }
                            else
                            {
                                filename = dr["FtpFullFilePath"].ToString();
                            }

                            //查询FTP上的文件大小和现在的上次下载的是否一致,一致则继续下载,不一致则重新下载


                            if (File.Exists(dr["LocalFullFilePath"].ToString()) == false)
                            {
                                dgvList.Rows.Add(res.error, false, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(), "<ERROR>Can't find the source file, can't download",
                                                 dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["Type"].ToString(), dr["ModifyDate"].ToString());
                            }
                            else
                            {
                                FileInfo currlocalfileinfo = new FileInfo(dr["LocalFullFilePath"].ToString());

                                if (currlocalfileinfo.Length.ToString() != dr["FileSize"].ToString() ||
                                    currlocalfileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") != dr["ModifyDate"].ToString())
                                {
                                    DB.SaveUploadlist(sitename, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), lblFtpPath.Text, dr["Type"].ToString(), currlocalfileinfo.Length.ToString(), dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), currlocalfileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"));
                                    dgvList.Rows.Add(res.wait, false, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), currlocalfileinfo.Length.ToString(), "<!>The source file has been changed, need reupload",
                                                     dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["Type"].ToString(), currlocalfileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"));
                                }
                                else
                                {
                                    DataTable dtFtpFileInfo = (type == "FTP") ? Ftp.GetFileList(filename) : sFtp.GetFileList(filename);
                                    if (dtFtpFileInfo != null && dtFtpFileInfo.Rows.Count > 0)
                                    {
                                        //fi的长度就是offset
                                        dgvList.Rows.Add(res.wait, false, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(),
                                                         "<!>Upload finished " + Convert.ToInt32((Convert.ToDouble(dtFtpFileInfo.Rows[0]["Size"].ToString()) / Convert.ToDouble(currlocalfileinfo.Length)) * 100).ToString() + "%",
                                                         dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["Type"].ToString(), dr["ModifyDate"].ToString());
                                    }
                                    else
                                    {
                                        DB.SaveUploadlist(sitename, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), lblFtpPath.Text, dr["Type"].ToString(), dr["FileSize"].ToString(), dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["ModifyDate"].ToString());
                                        dgvList.Rows.Add(res.wait, false, dr["LocalPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(), "<!>Can't find the last upload file, need reupload",
                                                         dr["LocalFullFilePath"].ToString(), dr["FtpFullFilePath"].ToString(), dr["Type"].ToString(), dr["ModifyDate"].ToString());
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    lblStatus.Text = "Getting files list for upload, please wait...";
                    Thread.Sleep(300);
                    Application.DoEvents();

                    #region read files and folders
                    foreach (DataRow dr in dtChoosedList.Rows)
                    {
                        string localpath = dr["LocalPath"].ToString();
                        if (localpath.EndsWith("\\"))
                        {
                            localpath = localpath.Substring(0, localpath.Length - 1);
                        }
                        if (dr["IsFolder"].ToString() == "Y")
                        {
                            string ipath = localpath.Substring(0, localpath.LastIndexOf("\\"));
                            //try
                            //{
                            //    ftp.MakeFolder(LocalFileFolder, RemoteFileFolder, ipath);//如果源是文件夹,则连源文件夹一起上传
                            //}
                            //catch { }
                            DoWhileLocalIsFolder(ftppathwithoutip, localpath, initiallocalpath);
                        }
                        else
                        {
                            //只上传指定文件
                            //ftp.Upload(o, iRow, RemoteFileFolder, LocalFileFolder, truelocalfilefolder);

                            //是文件的,要把文件名从路径中去掉,显示在界面上
                            DataRow drFile = dtAllFiles.NewRow();
                            if (localpath.LastIndexOf("\\") < 0)
                            {
                                drFile["LocalPath"] = "";
                                drFile["File Name"] = localpath;
                            }
                            else
                            {
                                drFile["LocalPath"] = localpath.Substring(0, localpath.LastIndexOf("\\"));
                                drFile["File Name"] = localpath.Substring(localpath.LastIndexOf("\\") + 1, localpath.Length - localpath.LastIndexOf("\\") - 1);
                            }
                            drFile["Size"]            = dr["Size"].ToString();
                            drFile["Type"]            = dr["Type"].ToString();
                            drFile["Modify Date"]     = dr["Modify Date"].ToString();
                            drFile["FileFullPath"]    = dr["FileFullPath"].ToString();
                            drFile["IsFolder"]        = "N";
                            drFile["FtpFullFilePath"] = GetFtpFullPath(new FileInfo(dr["FileFullPath"].ToString()), null, initiallocalpath, ftppathwithoutip);    //文件夹第一层这个路径就是文件路径了,不用再加文件名
                            dtAllFiles.Rows.Add(drFile);
                        }
                    }
                    #endregion

                    foreach (DataRow drallfile in dtAllFiles.Rows)
                    {
                        DataGridViewCheckBoxColumn dgvcc = new DataGridViewCheckBoxColumn();
                        dgvcc.HeaderText = "";
                        dgvcc.Resizable  = DataGridViewTriState.False;

                        dgvList.Rows.Add(res.wait, false, drallfile["LocalPath"].ToString(), drallfile["File Name"].ToString(), drallfile["Size"].ToString(), "",
                                         drallfile["FileFullPath"].ToString(), drallfile["FtpFullFilePath"].ToString(), drallfile["Type"].ToString(), drallfile["Modify Date"].ToString());
                    }
                }

                dgvList.ClearSelection();
                chkAll.Checked = true;
                lblTotal.Text  = dgvList.Rows.Count.ToString();
                lblStatus.Text = "Get files list finished";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Download", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                btnUpload.Enabled = true;
                this.Cursor       = Cursors.Default;
            }
        }
Exemple #3
0
        private void t_prepare_Tick(object sender, EventArgs e)
        {
            try
            {
                t_prepare.Enabled = false;

                this.Cursor = Cursors.AppStarting;

                clickbychkall = true;
                //在读取文件的时候读取空文件夹,因为读取文件列表的时候空文件夹不在文件列表中,会造成空文件夹上传丢失

                lblStatus.Text = "Getting site profile...";
                Application.DoEvents();
                using (DataTable dt = DB.GetSiteProfileDetail(sitename))
                {
                    type = dt.Rows[0]["Type"].ToString();
                    //if (type == "SFTP")
                    //{
                    //    btnPause.Text = "Exit";
                    //}
                    siteip     = dt.Rows[0]["SiteIP"].ToString();
                    userid     = dt.Rows[0]["UserID"].ToString();
                    pwd        = Security.Decrypt(dt.Rows[0]["Password"].ToString());
                    renamefile = dt.Rows[0]["RenameFile"].ToString();
                    port       = dt.Rows[0]["Port"].ToString();
                }

                lblStatus.Text = "Creating " + type + " instance...";
                if (type == "FTP")
                {
                    Ftp = new FTP.FTP(sitename, siteip, userid, pwd, port, renamefile, "Override");
                }
                else
                {
                    sFtp = new SFTP.SFTP(sitename, siteip, userid, pwd, port, renamefile, "Override");
                    sFtp.Connect();
                }
                Thread.Sleep(300);
                Application.DoEvents();

                if (dtChoosedList == null)
                {
                    #region Continue download
                    btnDownload.Text  = "Continue download";
                    btnDownload.Width = 129;
                    btnDownload.Left  = 702;
                    btnPause.Left     = 640;
                    lblStatus.Text    = "Getting breakpoint resume files list...";
                    Thread.Sleep(300);
                    Application.DoEvents();

                    dtAllResumeFiles = DB.GetDownloadBreakpointResumeFileList(sitename);
                    if (dtAllResumeFiles.Rows.Count > 0)
                    {
                        lblLocalPath.Text = dtAllResumeFiles.Rows[0]["LocalPath"].ToString();
                    }
                    foreach (DataRow dr in dtAllResumeFiles.Rows)
                    {
                        //取得文件列表后,检索本地文件下载情况。
                        if (dr["Type"].ToString() == "File Folder")
                        {
                            if (Directory.Exists(dr["LocalFullFilePath"].ToString()) == false)
                            {
                                DB.SaveDownloadlist(sitename, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), lblLocalPath.Text, dr["Type"].ToString(), dr["FileSize"].ToString(), dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["ModifyDate"].ToString());
                                dgvList.Rows.Add(res.wait, false, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(), "<!>Can't find the folder, need recreat",
                                                 dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["Type"].ToString(), dr["Modify Date"].ToString());
                            }
                        }
                        else
                        {
                            string filename = null;
                            if (renamefile == "Y")
                            {
                                filename = dr["LocalFullFilePath"].ToString() + ".tmp";
                            }
                            else
                            {
                                filename = dr["LocalFullFilePath"].ToString();
                            }

                            //查询FTP上的文件大小和现在的上次下载的是否一致,一致则继续下载,不一致则重新下载
                            using (DataTable dtCheckFtpFileStatus = (type == "FTP")?Ftp.GetFileList(dr["FtpFullFilePath"].ToString()):sFtp.GetFileList(dr["FtpFullFilePath"].ToString()))
                            {
                                if (dtCheckFtpFileStatus == null || dtCheckFtpFileStatus.Rows.Count == 0)
                                {
                                    dgvList.Rows.Add(res.error, false, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(), "<ERROR>Can't find the source file, can't download",
                                                     dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["Type"].ToString(), dr["Modify Date"].ToString());
                                }
                                else
                                {
                                    if (dtCheckFtpFileStatus.Rows[0]["Size"].ToString() != dr["FileSize"].ToString() ||
                                        dtCheckFtpFileStatus.Rows[0]["Modify Date"].ToString() != dr["ModifyDate"].ToString())
                                    {
                                        DB.SaveDownloadlist(sitename, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), lblLocalPath.Text, dr["Type"].ToString(), dtCheckFtpFileStatus.Rows[0]["Size"].ToString(), dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dtCheckFtpFileStatus.Rows[0]["Modify Date"].ToString());
                                        dgvList.Rows.Add(res.wait, false, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dtCheckFtpFileStatus.Rows[0]["Size"].ToString(), "<!>The source file has been changed, need redownload",
                                                         dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["Type"].ToString(), dtCheckFtpFileStatus.Rows[0]["Modify Date"].ToString());
                                    }
                                    else
                                    {
                                        if (File.Exists(filename))
                                        {
                                            FileInfo fi = new FileInfo(filename);
                                            //fi的长度就是offset
                                            dgvList.Rows.Add(res.wait, false, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(),
                                                             "<!>Download finished " + Convert.ToInt32((Convert.ToDouble(fi.Length) / Convert.ToDouble(dr["FileSize"].ToString())) * 100).ToString() + "%",
                                                             dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["Type"].ToString(), dr["ModifyDate"].ToString());
                                        }
                                        else
                                        {
                                            DB.SaveDownloadlist(sitename, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), lblLocalPath.Text, dr["Type"].ToString(), dr["FileSize"].ToString(), dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["ModifyDate"].ToString());
                                            dgvList.Rows.Add(res.wait, false, dr["FtpPath"].ToString(), dr["FileNameWithoutPath"].ToString(), dr["FileSize"].ToString(), "<!>Can't find the last download file, need redownload",
                                                             dr["FtpFullFilePath"].ToString(), dr["LocalFullFilePath"].ToString(), dr["Type"].ToString(), dr["ModifyDate"].ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    lblStatus.Text = "Getting files list for download, please wait...";
                    Thread.Sleep(300);
                    Application.DoEvents();

                    #region read files and folders
                    foreach (DataRow dr in dtChoosedList.Rows)
                    {
                        string ftppath = dr["FtpPath"].ToString();
                        ftppath = ftppath.Substring(sitename.Length, ftppath.Length - sitename.Length);
                        while (ftppath.StartsWith("/"))
                        {
                            ftppath = ftppath.Substring(1, ftppath.Length - 1);
                        }
                        int    ilast;
                        string tmpremotefolder;
                        if (ftppath.EndsWith("/"))
                        {
                            tmpremotefolder = ftppath.Substring(0, ftppath.Length - 1);
                        }
                        else
                        {
                            tmpremotefolder = ftppath;
                        }
                        //本地需要建立下载目录同名的目录,就是将选中的FTP文件夹在本地建立,而不只是下载FTP文件夹里面的内容
                        ilast = tmpremotefolder.LastIndexOf("/");
                        string ipath       = ftppath.Substring(ilast + 1, tmpremotefolder.Length - ilast - 1);
                        string localfolder = lblLocalPath.Text + "\\" + ipath;

                        if (dr["IsFolder"].ToString() == "Y")
                        {
                            DoWhileRemoteIsFolder(ftppath, localfolder);
                        }
                        else
                        {
                            //是文件的,要把文件名从路径中去掉,显示在界面上
                            DataRow drFile = dtAllFiles.NewRow();
                            if (ftppath.LastIndexOf("/") < 0)
                            {
                                drFile["FtpPath"]   = "/";
                                drFile["File Name"] = ftppath;
                            }
                            else
                            {
                                drFile["FtpPath"]   = ftppath.Substring(0, ftppath.LastIndexOf("/"));
                                drFile["File Name"] = ftppath.Substring(ftppath.LastIndexOf("/") + 1, ftppath.Length - ftppath.LastIndexOf("/") - 1);
                            }
                            drFile["Size"]              = dr["Size"].ToString();
                            drFile["Type"]              = dr["Type"].ToString();
                            drFile["Modify Date"]       = dr["Modify Date"].ToString();
                            drFile["FileFullPath"]      = dr["FileFullPath"].ToString();
                            drFile["IsFolder"]          = "N";
                            drFile["LocalFullFilePath"] = localfolder;//文件夹第一层这个路径就是文件路径了,不用再加文件名
                            dtAllFiles.Rows.Add(drFile);
                        }
                    }
                    #endregion

                    foreach (DataRow drallfile in dtAllFiles.Rows)
                    {
                        DataGridViewCheckBoxColumn dgvcc = new DataGridViewCheckBoxColumn();
                        dgvcc.HeaderText = "";
                        dgvcc.Resizable  = DataGridViewTriState.False;

                        dgvList.Rows.Add(res.wait, false, drallfile["FtpPath"].ToString(), drallfile["File Name"].ToString(), drallfile["Size"].ToString(), "",
                                         drallfile["FileFullPath"].ToString(), drallfile["LocalFullFilePath"].ToString(), drallfile["Type"].ToString(), drallfile["Modify Date"].ToString());
                    }
                }

                dgvList.ClearSelection();
                chkAll.Checked = true;
                lblTotal.Text  = dgvList.Rows.Count.ToString();
                lblStatus.Text = "Get files list finished";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Download", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                btnDownload.Enabled = true;
                this.Cursor         = Cursors.Default;
            }
        }
Exemple #4
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            btnDownload.Enabled = false;
            btnPause.Enabled    = true;
            chkAll.Enabled      = false;
            btnAbort.Enabled    = false;

            try
            {
                //SetSelectCellStatus(true);
                dgvList.Enabled = false;
                if (btnDownload.Text.ToUpper().EndsWith("DOWNLOAD"))
                {
                    lblStatus.Text = "Saving the download list, please wait...";
                    Application.DoEvents();
                    try
                    {
                        if (callbyPause == false)
                        {
                            DB.DeleteAllUnfinishedDownloadItem(sitename);
                            foreach (DataGridViewRow dgvr in dgvList.Rows)
                            {
                                if ((bool)dgvr.Cells[1].Value == true)
                                {
                                    if (dgvr.Cells["Status"].Value.ToString() == "" || dgvr.Cells["Status"].Value.ToString().StartsWith("<!>"))
                                    {
                                        DB.SaveDownloadlist(sitename, dgvr.Cells["FtpPath"].Value.ToString(), dgvr.Cells["FileName"].Value.ToString(),
                                                            lblLocalPath.Text, dgvr.Cells["Type"].Value.ToString(), dgvr.Cells["Size"].Value.ToString(),
                                                            dgvr.Cells["FileFullName"].Value.ToString(), dgvr.Cells["LocalFullFileName"].Value.ToString(), dgvr.Cells["ModifyDate"].Value.ToString());
                                    }
                                }
                                //dgvr.Cells["Status"].Value = "";
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    lblStatus.Text = "Start downloading...";
                    if (callbyPause == false)
                    {
                        lblFinished.Text = "0";
                    }
                    else
                    {
                        callbyPause = false;
                    }

                    //向上滚动DGV
                    int idgvX = 0, idgvY = 0, iCellX = 0, iCellY = 0;
                    idgvX = dgvList.Location.X;
                    idgvY = dgvList.Location.Y;
                    bool b_Move    = false;
                    int  iRowCount = -1;
                    dgvList.FirstDisplayedScrollingRowIndex = 0;

                    for (int i = 0; i < dgvList.Rows.Count; i++)
                    {
                        if (btnPause.Text == "Start")
                        {
                            break;
                        }
                        #region //向上滚动
                        if (b_Move)
                        {
                            dgvList.FirstDisplayedScrollingRowIndex = dgvList.Rows[i].Index - iRowCount;
                        }
                        iCellX = dgvList.GetCellDisplayRectangle(0, dgvList.Rows[i].Index, false).X;
                        iCellY = dgvList.GetCellDisplayRectangle(0, dgvList.Rows[i].Index, false).Y;

                        //如果得到的单元格的Y坐标=0了,说明到底了,要开始往上移动
                        //如果得到的单元格的Y坐标加上单元格高度比控件高度高了,要开始往上移动
                        //一旦开始移动,则每个循环都要移动了
                        //2倍的单元格高度,因为到底后可能出现横向滚动条,多以提早开始移动
                        if (iCellY == 0 || idgvY + iCellY + dgvList.Rows[i].Cells[0].Size.Height + dgvList.Rows[i].Cells[0].Size.Height > idgvY + dgvList.Height)
                        {
                            dgvList.FirstDisplayedScrollingRowIndex = dgvList.Rows[i].Index - iRowCount;
                            iCellY = dgvList.GetCellDisplayRectangle(0, dgvList.Rows[i].Index, false).Y;
                            b_Move = true;
                        }
                        else
                        {
                            if (b_Move == false)
                            {
                                iRowCount++;
                            }
                        }
                        #endregion

                        if ((bool)dgvList.Rows[i].Cells[1].Value == true
                            &&
                            (dgvList.Rows[i].Cells["Status"].Value.ToString().StartsWith("<OK>") == false && dgvList.Rows[i].Cells["Status"].Value.ToString().StartsWith("<ERROR>") == false))//download
                        {
                            try
                            {
                                ResetStructCurrentDownload();
                                currentdownloadinfo.SiteName            = sitename;
                                currentdownloadinfo.FtpPath             = dgvList.Rows[i].Cells["FtpPath"].Value.ToString();
                                currentdownloadinfo.FileNameWithoutPath = dgvList.Rows[i].Cells["FileName"].Value.ToString();
                                currentdownloadinfo.LocalPath           = lblLocalPath.Text;
                                currentdownloadinfo.Type              = dgvList.Rows[i].Cells["Type"].Value.ToString();
                                currentdownloadinfo.FileSize          = Convert.ToInt32(dgvList.Rows[i].Cells["Size"].Value);
                                currentdownloadinfo.LocalFullFileName = dgvList.Rows[i].Cells["LocalFullFileName"].Value.ToString();

                                if (currentdownloadinfo.Type == "File Folder")
                                {
                                    if (Directory.Exists(currentdownloadinfo.LocalFullFileName) == false)
                                    {
                                        Directory.CreateDirectory(currentdownloadinfo.LocalFullFileName);
                                    }
                                    DB.Deletedownloaditem(currentdownloadinfo.SiteName, currentdownloadinfo.FtpPath, currentdownloadinfo.FileNameWithoutPath);
                                    dgvList.Rows[i].Cells[0].Value        = res.ok;
                                    dgvList.Rows[i].Cells["Status"].Value = "<OK>Finished";
                                }
                                else
                                {
                                    if (renamefile == "Y")
                                    {
                                        currentdownloadinfo.CurrentUsedLocalFullFileName = dgvList.Rows[i].Cells["LocalFullFileName"].Value.ToString() + ".tmp";
                                    }
                                    else
                                    {
                                        currentdownloadinfo.CurrentUsedLocalFullFileName = dgvList.Rows[i].Cells["LocalFullFileName"].Value.ToString();
                                    }
                                    dgvList.Rows[i].Cells[0].Value = res.download;

                                    int finishedlength = 0;
                                    if (dgvList.Rows[i].Cells["Status"].Value.ToString() != "")
                                    {
                                        if (File.Exists(currentdownloadinfo.CurrentUsedLocalFullFileName))
                                        {
                                            finishedlength = (int)(new FileInfo(currentdownloadinfo.CurrentUsedLocalFullFileName)).Length;
                                        }
                                    }
                                    string localfilepath = currentdownloadinfo.LocalFullFileName.Substring(0, currentdownloadinfo.LocalFullFileName.Length - currentdownloadinfo.FileNameWithoutPath.Length - 1);
                                    if (Directory.Exists(localfilepath) == false)
                                    {
                                        Directory.CreateDirectory(localfilepath);
                                    }
                                    if (type == "FTP")
                                    {
                                        Ftp.Download(this, i, localfilepath,
                                                     dgvList.Rows[i].Cells["FileName"].Value.ToString(),
                                                     dgvList.Rows[i].Cells["FileFullName"].Value.ToString(), finishedlength);
                                    }
                                    else
                                    {
                                        sFtp.Download(this, i, localfilepath,
                                                      dgvList.Rows[i].Cells["FileName"].Value.ToString(),
                                                      dgvList.Rows[i].Cells["FileFullName"].Value.ToString(), finishedlength);
                                        sFtp = null;
                                        sFtp = new SFTP.SFTP(sitename, siteip, userid, pwd, port, renamefile, "Override");
                                        sFtp.Connect();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                try
                                {
                                    dgvList.Rows[i].Cells[0].Value        = res.error;
                                    dgvList.Rows[i].Cells["Status"].Value = "<ERROR>" + ex.Message;
                                    DB.Deletedownloaditem(currentdownloadinfo.SiteName, currentdownloadinfo.FtpPath, currentdownloadinfo.FileNameWithoutPath);
                                }
                                catch { }
                            }
                            finally
                            {
                                try
                                {
                                    lblFinished.Text = (Convert.ToInt32(lblFinished.Text) + 1).ToString();
                                }
                                catch { }
                                Application.DoEvents();
                            }
                        }
                    }
                }
            }
            finally
            {
                if (btnPause.Text != "Start")
                {
                    //SetSelectCellStatus(false);
                    dgvList.Enabled     = true;
                    btnPause.Enabled    = false;
                    btnDownload.Enabled = true;
                    chkAll.Enabled      = true;
                    btnAbort.Enabled    = true;
                    MessageBox.Show("Download finished", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }