Ejemplo n.º 1
0
        private bool SFTPDownload_DownloadFile(
            string remoteFullPath, string fileName, string localFileFullPath,
            SFTPFileAttributes fileAttr, ref bool overwite)
        {
            if (IsFileTransferCanceled())
            {
                Log("Canceled");
                return(false);   // cancel
            }

            if (!overwite)
            {
                bool existence = File.Exists(localFileFullPath);

                if (existence)
                {
                    DialogResult result = DialogResult.None;
                    this.Invoke((MethodInvoker) delegate() {
                        string caption = SFTPPlugin.Instance.StringResource.GetString("SFTPForm.Confirmation");
                        string format  = SFTPPlugin.Instance.StringResource.GetString("SFTPForm.AskOverwriteFormat");
                        string message = String.Format(format, localFileFullPath);

                        using (YesNoAllDialog dialog = new YesNoAllDialog(message, caption)) {
                            result = dialog.ShowDialog(this);
                        }
                    });

                    if (result == DialogResult.Cancel)
                    {
                        Log("Canceled");
                        return(false);   // cancel
                    }
                    if (result == DialogResult.No)
                    {
                        Log(" | Skipped: " + localFileFullPath);
                        return(true);    // skip
                    }
                    if (result == YesNoAllDialog.YesToAll)
                    {
                        overwite = true;
                    }
                }
            }

            ulong fileSize = fileAttr.FileSize;

            _sftp.DownloadFile(remoteFullPath, localFileFullPath, _fileTransferCancellation,
                               delegate(SFTPFileTransferStatus status, ulong transmitted) {
                ShowProgress(localFileFullPath, fileName, status, fileSize, transmitted);
            });

            if (IsFileTransferCanceled())
            {
                return(false);   // canceled
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 2
0
 public void DownloadFiles(SFTPDownloadArgument[] downloadArguments, string host, string userName, string password, CallbackContext callbackContext)
 {
     try
     {
         Requires.NotNullOrEmpty(host, "remoteHost");
         Requires.NotNullOrEmpty(userName, "userName");
         Requires.NotNullOrEmpty(password, "password");
         foreach (SFTPDownloadArgument downloadArgument in downloadArguments)
         {
             string[] paths    = downloadArgument.RemotePathWithFileName.Split('/');
             string   fileName = paths[paths.Length - 1];
             m_Logger.Debug($"downloadArgument:{downloadArgument}");
             Requires.NotNull(downloadArgument, "downloadArgument");
             Requires.NotNullOrEmpty(downloadArgument.RemotePathWithFileName, "remotePathWithFileName");
             Requires.NotNullOrEmpty(downloadArgument.LocalPathWithoutFileName, "localPathWithoutFileName");
             if (File.Exists(downloadArgument.LocalPathWithoutFileName + "\\" + fileName))
             {
                 File.Delete(downloadArgument.LocalPathWithoutFileName + "\\" + fileName);
             }
         }
         List <FtpStatusCode> result = new List <FtpStatusCode>();
         _sftpClient = GetInstance(host, userName, password);
         foreach (SFTPDownloadArgument downloadArgument in downloadArguments)
         {
             var sftpResult = _sftpClient.DownloadFile(downloadArgument.RemotePathWithFileName, downloadArgument.LocalPathWithoutFileName);
             result.Add(sftpResult);
         }
         callbackContext.Success(new PluginResult(PluginResult.Status.OK, result));
     }
     catch (Exception ex)
     {
         m_Logger.Error(ex);
         callbackContext.Error(new
         {
             type    = "Exception",
             code    = "",
             message = ex.Message,
             details = ex.StackTrace
         });
     }
 }
Ejemplo n.º 3
0
        private FtpStatusCode DownloadFile(SFTPDownloadArgument downloadArgument)
        {
            m_Logger.Debug($"downloadArgument:{downloadArgument}");
            string[] paths    = downloadArgument.RemotePathWithFileName.Split('/');
            string   fileName = paths[paths.Length - 1];

            Requires.NotNull(downloadArgument, "downloadArgument");
            Requires.NotNullOrEmpty(downloadArgument.RemoteHost, "remoteHost");
            Requires.NotNullOrEmpty(downloadArgument.RemotePathWithFileName, "remotePathWithFileName");
            Requires.NotNullOrEmpty(downloadArgument.LocalPathWithoutFileName, "localPathWithoutFileName");
            Requires.NotNullOrEmpty(downloadArgument.UserName, "userName");
            Requires.NotNullOrEmpty(downloadArgument.Password, "password");
            m_Logger.Debug("本地文件路径:" + downloadArgument.LocalPathWithoutFileName + "\\" + fileName);
            if (File.Exists(downloadArgument.LocalPathWithoutFileName + "\\" + fileName))
            {
                File.Delete(downloadArgument.LocalPathWithoutFileName + "\\" + fileName);
            }
            _sftpClient = GetInstance(downloadArgument.RemoteHost, downloadArgument.UserName, downloadArgument.Password);
            var sftpResult = _sftpClient.DownloadFile(downloadArgument.RemotePathWithFileName, downloadArgument.LocalPathWithoutFileName);

            return(sftpResult);
        }