예제 #1
0
        void Download(string fileName, string filePath)
        {
            _loadingUserControl.Show(this);

            _loadingUserControl.Message = "正在准备下载文件...";

            Task.Run(() =>
            {
                try
                {
                    _client.Download(fileName, Path.Combine(filePath, fileName), (o, c) =>
                    {
                        _loadingUserControl.Message = $"正在下载文件:{fileName},{(o * 100 / c)}%";
                    });

                    Log("下载文件成功,fileName:" + fileName);

                    textBox1_TextChanged(null, null);
                }
                catch (Exception ex)
                {
                    Log("下载文件失败,fileName:" + fileName, ex.Message);
                }
                finally
                {
                    _loadingUserControl.Hide(this);
                }
            });
        }
예제 #2
0
        void Download(string fileName, string filePath)
        {
            _loadingUserControl.Show(this);

            _loadingUserControl.Message = "正在准备下载文件...";

            Log($"正在准备下载文件{fileName}...");

            Task.Run(() =>
            {
                try
                {
                    _client.Download(fileName, Path.Combine(filePath, fileName), (o, c) =>
                    {
                        _loadingUserControl.Message = $"正在下载文件:{fileName},{(o * 100 / c)}%";
                    });

                    Log($"下载文件{fileName}成功");

                    RefreshLocalListView();
                }
                catch (Exception ex)
                {
                    Log("下载文件失败,fileName:" + fileName, ex.Message);
                }
                finally
                {
                    _loadingUserControl.Hide(this);
                }
            });
        }
예제 #3
0
        /// <summary>
        /// 右键另存为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuSaveAs_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            string            name     = menuItem.Tag.ToString();
            SaveFileDialog    sfd      = new SaveFileDialog()
            {
                FileName         = name,
                Filter           = "All Files|(*.*)",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                Title            = "另存为"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                //下载文件
                string filePath = sfd.FileName + ".temp";
                ftpClient.RelatePath = string.Format("{0}/{1}", ftpClient.RelatePath, name);
                try
                {
                    long size = 0;
                    if (File.Exists(filePath))
                    {
                        using (FileStream outputStream = new FileStream(filePath, FileMode.Open))
                        {
                            size = outputStream.Length;
                        }
                    }
                    //Thread threadDownload = new Thread(() => ftpClient.Download(filePath, size,updateProgress));
                    //threadDownload.Start();
                    //Thread threadWait = new Thread(() =>
                    //{
                    //    threadDownload.Join();
                    //    MessageBox.Show("下载完成");
                    //});
                    //threadWait.Start();
                    ftpClient.Download(filePath, size, updateProgress);
                    //MessageBox.Show("下载完成");

                    File.Delete(filePath.Substring(0, filePath.Length - 5));
                    FileInfo fileInfo = new FileInfo(filePath);
                    fileInfo.MoveTo(filePath.Substring(0, filePath.Length - 5));

                    lblMsg.Text = "下载完成";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    lblMsg.Text = "下载失败";
                }
            }
        }
예제 #4
0
 public byte[] ConnectToDownload()
 {
     //if (url != null)StartCoroutine (DownloadFromFTP ());
     //DownloadFromFTP ();
     ftp = new FTPClient("ftp://" + url + ":2121/sdcard/Pictures/structure.jpg", "collar", "password");
     //Debug.Log ("FTPload URL:" + url);
     ftp.Download();
     if (ftp.complete)
     {
         ftp.complete = false;
         return(ftp.raw);
     }
     else
     {
         Debug.Log("ftp.raw is NULL...");
         return(ftp.raw);
     }
 }
예제 #5
0
    public Exception Download_BackupFile(Info_FTPServer fTPServer)
    {
        try
        {
            bool isOK = FTPClient.Download(fTPServer.URL + "BackupDB_zip/" + ServerSource + "/" + DateTime.Now.ToString("yyyy-MM-dd"), fTPServer.User, fTPServer.Pass, AppDomain.CurrentDomain.BaseDirectory + @"Download\", DBSource + ".zip");

            if (isOK != true)
            {
                return(new Exception("Download Backup file failed!", new Exception("")));
            }
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + DBSource + ".bak"))
            {
                File.Delete(AppDomain.CurrentDomain.BaseDirectory + DBSource + ".bak");
            }

            ZipFile.ExtractToDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Download\" + DBSource + ".zip", AppDomain.CurrentDomain.BaseDirectory);
        }
        catch (Exception op)
        {
            return(new Exception(op.Message, op.InnerException));
        }
        return(null);
    }
예제 #6
0
        public static bool Download(string fileName, string localFile, bool deleteOld = true)
        {
            FTPClient ftpClient = new FTPClient(ftpServer, ftpUser, ftpPass);

            return(ftpClient.Download(fileName, localFile, deleteOld));
        }