Exemplo n.º 1
0
        public static FtpTransferOptions Default()
        {
            var ret = new FtpTransferOptions();

            ret.BufferSize        = 2048;
            ret.Overwrite         = OverwriteExisting.No;
            ret.ShowTotalProgress = true;
            ret.SupressErrors     = false;

            return(ret);
        }
Exemplo n.º 2
0
        public static FtpTransferOptions FromBytes(byte[] bytes)
        {
            if (bytes.Length != 10)
            {
                throw new ApplicationException(Options.GetLiteral(Options.LANG_CANNOT_READ_FTP_TRANSFER_SETTINGS));
            }

            var ret = new FtpTransferOptions();

            ret.BufferSize        = (int)BitConverter.ToInt64(bytes, 0);
            ret.SupressErrors     = BitConverter.ToBoolean(bytes, 4);
            ret.ShowTotalProgress = BitConverter.ToBoolean(bytes, 5);
            ret.Overwrite         = (OverwriteExisting)BitConverter.ToInt64(bytes, 6);

            return(ret);
        }
Exemplo n.º 3
0
 public FtpDownloadEngine
     (FtpEntryInfo[] source,
     string destination,
     FtpConnection connection,
     FtpTransferOptions opts,
     CopyFileProgressDialog progress_window)
 {
     initial_source                  = source;
     initial_destination             = destination;
     this.connection                 = connection;
     this.opts                       = opts;
     progress                        = progress_window;
     thread_background               = new Thread(new ThreadStart(internal_do));
     update_progress_delegate_holder = new MethodInvokerUpdateProgress(update_progress);
     if (progress_window != null)
     {
         progress_window.FormClosing += new FormClosingEventHandler(progress_dialog_FormClosing);
     }
     transfer_progress_delegate_holder = new FtpTransferProgress(ftp_transfer_proc);
 }
Exemplo n.º 4
0
        private void upload_to_ftp(QueryPanelInfoEventArgs e_current, QueryPanelInfoEventArgs e_other)
        {
            DirectoryList    source_directory = (DirectoryList)e_current.ItemCollection;
            FtpDirectoryList destination_ftp  = (FtpDirectoryList)e_other.ItemCollection;

            List <string> source_list = new List <string>();

            if (e_current.SelectedIndices.Length == 0)
            {
                if (source_directory.GetItemDisplayNameLong(e_current.FocusedIndex) == "..")
                {
                    return;
                }

                source_list.Add
                    (Path.Combine
                        (source_directory.DirectoryPath,
                        source_directory.GetItemDisplayNameLong(e_current.FocusedIndex)));
            }
            else
            {
                for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                {
                    source_list.Add
                        (Path.Combine
                            (source_directory.DirectoryPath,
                            source_directory.GetItemDisplayNameLong(e_current.SelectedIndices[i])));
                }
            }

            string        dest_path = destination_ftp.DirectoryPath;
            FtpConnection ftp_conn  = destination_ftp.Connection;

            //show upload dialog
            FtpTransferOptions ftp_trans_opts = Options.FtpUploadOptions;
            FtpTransferDialog  dialog         = new FtpTransferDialog();

            dialog.FtpTransferOptions      = ftp_trans_opts;
            dialog.textBoxDestination.Text = dest_path;
            dialog.Text = Options.GetLiteral(Options.LANG_UPLOAD);
            if (source_list.Count == 1)
            {
                dialog.labelSourceFile.Text =
                    source_list[0];
            }
            else
            {
                dialog.labelSourceFile.Text =
                    string.Format
                        ("{0} " + Options.GetLiteral(Options.LANG_ENTRIES),
                        source_list.Count);
            }

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //retrieve user selection
            ftp_trans_opts = dialog.FtpTransferOptions;
            dest_path      = dialog.textBoxDestination.Text;

            //save user selection
            Options.FtpUploadOptions = ftp_trans_opts;


            //prepare progress window
            dialog_progress = new CopyFileProgressDialog();
            dialog_progress.labelError.Visible            = false;
            dialog_progress.labelSpeed.Text               = string.Empty;
            dialog_progress.labelStatus.Text              = string.Empty;
            dialog_progress.labelStatusTotal.Text         = string.Empty;
            dialog_progress.checkBoxCloseOnFinish.Checked = Options.CopyCloseProgress;

            dialog_progress.TopLevel = true;
            int x_center = Program.MainWindow.Left + Program.MainWindow.Width / 2;
            int y_center = Program.MainWindow.Top + Program.MainWindow.Height / 2;
            int x_dialog = x_center - dialog_progress.Width / 2;
            int y_dialog = y_center - dialog_progress.Height / 2;

            if (x_dialog < 0)
            {
                x_dialog = 0;
            }
            if (x_dialog < 0)
            {
                y_dialog = 0;
            }
            dialog_progress.Show();
            dialog_progress.Location = new System.Drawing.Point(x_dialog, y_dialog);

            //prepare upload engine
            FtpUploadEngine upload_engine = new FtpUploadEngine
                                                (source_list.ToArray(),
                                                dest_path,
                                                ftp_conn,
                                                ftp_trans_opts,
                                                dialog_progress);

            upload_engine.Done           += new EventHandler(upload_engine_Done);
            upload_engine.UploadItemDone += new ItemEventHandler(upload_engine_UploadItemDone);

            upload_engine.Run();

            //ftp_conn.ClearCache(dest_path);
        }
        protected override void internal_command_proc()
        {
            QueryPanelInfoEventArgs e_current = new QueryPanelInfoEventArgs();
            QueryPanelInfoEventArgs e_other   = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e_current);
            OnQueryOtherPanel(e_other);

            if (e_current.FocusedIndex == -1)
            {
                return;
            }

            if (!(e_other.ItemCollection is DirectoryList))
            {
                Messages.ShowMessage(Options.GetLiteral(Options.LANG_WRONG_DESTINATION));
                return;
            }

            FtpDirectoryList ftp_list = (FtpDirectoryList)e_current.ItemCollection;
            DirectoryList    dir_list = (DirectoryList)e_other.ItemCollection;

            List <FtpEntryInfo> sel_source = new List <FtpEntryInfo>();

            if (e_current.SelectedIndices.Length == 0)
            {
                sel_source.Add(ftp_list[e_current.FocusedIndex]);
            }
            else
            {
                for (int i = 0; i < e_current.SelectedIndices.Length; i++)
                {
                    sel_source.Add(ftp_list[e_current.SelectedIndices[i]]);
                }
            }

            string destination = dir_list.DirectoryPath;

            //prepare and show user dialog
            FtpTransferOptions ftp_trans_opts = Options.FtpDownloadOptions;
            FtpTransferDialog  dialog         = new FtpTransferDialog();

            dialog.FtpTransferOptions      = ftp_trans_opts;
            dialog.textBoxDestination.Text = destination;

            if (sel_source.Count == 1)
            {
                dialog.labelSourceFile.Text =
                    ftp_list.Connection.Options.ServerName + FtpPath.Combine(sel_source[0].DirectoryPath, sel_source[0].EntryName);
            }
            else
            {
                dialog.labelSourceFile.Text =
                    string.Format
                        ("{0} items from {1}",
                        sel_source.Count,
                        ftp_list.Connection.Options.ServerName);
            }

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //retrieve user selection
            ftp_trans_opts = dialog.FtpTransferOptions;
            destination    = dialog.textBoxDestination.Text;

            //save user selection
            Options.FtpDownloadOptions = ftp_trans_opts;

            //prepare progress window
            dialog_progress = new CopyFileProgressDialog();
            dialog_progress.labelError.Visible            = false;
            dialog_progress.labelSpeed.Text               = string.Empty;
            dialog_progress.labelStatus.Text              = string.Empty;
            dialog_progress.labelStatusTotal.Text         = string.Empty;
            dialog_progress.checkBoxCloseOnFinish.Checked = Options.CopyCloseProgress;

            dialog_progress.TopLevel = true;
            int x_center = Program.MainWindow.Left + Program.MainWindow.Width / 2;
            int y_center = Program.MainWindow.Top + Program.MainWindow.Height / 2;
            int x_dialog = x_center - dialog_progress.Width / 2;
            int y_dialog = y_center - dialog_progress.Height / 2;

            if (x_dialog < 0)
            {
                x_dialog = 0;
            }
            if (x_dialog < 0)
            {
                y_dialog = 0;
            }
            dialog_progress.Show();
            dialog_progress.Location = new System.Drawing.Point(x_dialog, y_dialog);

            //prepare doanload engine
            FtpDownloadEngine engine = new FtpDownloadEngine
                                           (sel_source.ToArray(),
                                           destination,
                                           ftp_list.Connection,
                                           ftp_trans_opts,
                                           dialog_progress);

            engine.Done             += new EventHandler(engine_Done);
            engine.DownloadItemDone += new ItemEventHandler(engine_DownloadItemDone);

            engine.Run();
        }