コード例 #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);
            }
        }
コード例 #2
0
ファイル: SFTPForm.cs プロジェクト: FNKGino/poderosa
        private bool SFTPUpload_UploadFile(string fileName, string localFileFullPath, string remoteFullPath, ref bool overwite)
        {
            if (IsFileTransferCanceled()) {
                Log("Canceled");
                return false;   // cancel
            }

            if (!overwite) {
                bool existence;
                try {
                    _sftp.GetFileInformations(remoteFullPath, true);
                    existence = true;
                }
                catch (SFTPClientException e) {
                    if (!IsSFTPError(e, SFTPStatusCode.SSH_FX_NO_SUCH_FILE))
                        throw;
                    existence = false;
                }

                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, remoteFullPath);

                        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;
                    }
                }
            }

            FileInfo localFileInfo = new FileInfo(localFileFullPath);
            ulong fileSize = (ulong)localFileInfo.Length;
            _sftp.UploadFile(localFileFullPath, remoteFullPath, _fileTransferCancellation,
                delegate(SFTPFileTransferStatus status, ulong transmitted) {
                    ShowProgress(localFileFullPath, fileName, status, fileSize, transmitted);
                });

            if (IsFileTransferCanceled())
                return false;   // canceled
            else
                return true;
        }
コード例 #3
0
        private bool SFTPUpload_UploadFile(string fileName, string localFileFullPath, string remoteFullPath, ref bool overwite)
        {
            if (IsFileTransferCanceled())
            {
                Log("Canceled");
                return(false);   // cancel
            }

            if (!overwite)
            {
                bool existence;
                try {
                    _sftp.GetFileInformations(remoteFullPath, true);
                    existence = true;
                }
                catch (SFTPClientException e) {
                    if (!IsSFTPError(e, SFTPStatusCode.SSH_FX_NO_SUCH_FILE))
                    {
                        throw;
                    }
                    existence = false;
                }

                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, remoteFullPath);

                        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;
                    }
                }
            }

            FileInfo localFileInfo = new FileInfo(localFileFullPath);
            ulong    fileSize      = (ulong)localFileInfo.Length;

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

            if (IsFileTransferCanceled())
            {
                return(false);   // canceled
            }
            else
            {
                return(true);
            }
        }
コード例 #4
0
ファイル: SFTPForm.cs プロジェクト: FNKGino/poderosa
        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;
        }