Example #1
0
        private long calc_dir_size(string dir_name)
        {
            var ret = 0L;

            //get file info list from server
            var dir_list = new List <FtpEntryInfo>();

            try
            {
                dir_list = connection.GetDirectoryDetailsList(dir_name, false);
            }
            catch (Exception ex)
            {
                AbortSafe = !process_error
                                (string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_READ_DIRECTORY_CONTENTS_0),
                                    dir_name),
                                ex);
            }
            if (!AbortSafe)
            {
                foreach (var info in dir_list)
                {
                    if (info.Directory)
                    {
                        ret += calc_dir_size(FtpPath.AppendEndingSeparator(FtpPath.Combine(info.DirectoryPath, info.EntryName)));
                    }
                    else
                    {
                        ret += info.Size;
                    }
                }
            }
            return(ret);
        }
Example #2
0
        public bool GetEntryInfo(string path_name, ref FtpEntryInfo info_to_fill, bool force_update)
        {
            string directory = FtpPath.GetDirectory(path_name);
            string file      = FtpPath.GetFile(path_name);
            bool   ret       = false;

            //get parent directory contents
            List <FtpEntryInfo> dir_list = new List <FtpEntryInfo>();

            try
            {
                dir_list = GetDirectoryDetailsList(FtpPath.AppendEndingSeparator(directory), force_update);
            }
            catch { } //supress all errors

            //find entry
            foreach (FtpEntryInfo info in dir_list)
            {
                if (info.EntryName == file)
                {
                    info_to_fill = info.Clone();
                    ret          = true;
                }
            }

            return(ret);
        }
Example #3
0
        private long calc_source_size()
        {
            var ret = 0L;

            foreach (var info in initial_source)
            {
                if (info.Directory)
                {
                    ret += calc_dir_size(FtpPath.AppendEndingSeparator(FtpPath.Combine(info.DirectoryPath, info.EntryName)));
                }
                else
                {
                    ret += info.Size;
                }
            }

            //notify about source size calculated
            var e = new UpdateProgressArgs();

            e.EnableTotalProgress = opts.ShowTotalProgress;
            e.Reason    = UpdateProgressReason.TotalSizeCalculated;
            e.TotalSize = (ulong)ret;
            update_progress_safe(e);

            return(ret);
        }
Example #4
0
 private void cache_remove(string directory)
 {
     directory = FtpPath.AppendEndingSeparator(directory);
     lock (cache_lock)
     {
         if (internal_cache.ContainsKey(directory))
         {
             internal_cache.Remove(directory);
         }
     }
 }
Example #5
0
        private void download_directory(FtpEntryInfo source_dir_info, string dest_dir)
        {
            //we need list of dir contents
            var contents  = new List <FtpEntryInfo>();
            var dest_file = string.Empty;

            try
            {
                contents = connection.GetDirectoryDetailsList
                               (FtpPath.AppendEndingSeparator
                                   (FtpPath.Combine(source_dir_info.DirectoryPath, source_dir_info.EntryName)),
                               true);
            }
            catch (Exception ex)
            {
                AbortSafe = !process_error
                                (string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_READ_DIRECTORY_CONTENTS_0),
                                    FtpPath.Combine(source_dir_info.DirectoryPath, source_dir_info.EntryName)),
                                ex);
            }

            //if success
            foreach (var info in contents)
            {
                if (AbortSafe)
                {
                    break;
                }

                dest_file = Path.Combine(dest_dir, info.EntryName);
                if (info.Directory)
                {
                    //directory - call recursively
                    download_directory(info, dest_file);
                }
                else
                {
                    //that is file
                    download_one_file
                        (info,
                        dest_file);
                }
            }
        }
Example #6
0
 protected override void internal_refill()
 {
     try
     {
         OnLongOperaion("Wait while retrive file list from server...", true);
         List <FtpEntryInfo> entry_list =
             internal_conection.GetDirectoryDetailsList
                 (FtpPath.AppendEndingSeparator(internal_directory_path),
                 false);
         internal_list.Clear();
         foreach (FtpEntryInfo info in entry_list)
         {
             internal_list.Add(info, null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         OnLongOperaion("Completed.", false);
     }
 }
Example #7
0
 protected override void internal_refill()
 {
     try
     {
         OnLongOperaion(Options.GetLiteral(Options.LANG_FTP_WAIT_RETRIEVE_DIRECTORY_LIST), true);
         var entry_list =
             internal_conection.GetDirectoryDetailsList
                 (FtpPath.AppendEndingSeparator(internal_directory_path),
                 false);
         internal_list.Clear();
         foreach (var info in entry_list)
         {
             internal_list.Add(info, null);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         OnLongOperaion(string.Empty, false);
     }
 }
Example #8
0
        private void delete_recursive(FtpEntryInfo info, mainForm main_window)
        {
            if (abort)
            {
                return;
            }

            if (info.Directory)
            {
                //first we must delete all contents of directory
                //get contents
                //and notify main window
                if (main_window != null)
                {
                    main_window.NotifyLongOperation
                        (string.Format
                            (Options.GetLiteral(Options.LANG_FTP_WAIT_RETRIEVE_DIRECTORY_LIST)),
                        true);
                }
                List <FtpEntryInfo> contents = new List <FtpEntryInfo>();
                try
                {
                    contents =
                        connection.GetDirectoryDetailsList
                            (FtpPath.AppendEndingSeparator(FtpPath.Combine(info.DirectoryPath, info.EntryName)), true);
                }
                catch (Exception ex)
                {
                    abort = !process_error
                                (string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_READ_DIRECTORY_CONTENTS_0),
                                    FtpPath.Combine(info.DirectoryPath, info.EntryName)),
                                ex);
                }
                if (abort)
                {
                    return;
                }
                foreach (FtpEntryInfo current_info in contents)
                {
                    delete_recursive(current_info, main_window);
                    if (abort)
                    {
                        return;
                    }
                }
                //and after this we can remove directory
                main_window.NotifyLongOperation
                    (string.Format
                        (Options.GetLiteral(Options.LANG_DELETE_NOW_0),
                        FtpPath.Combine(info.DirectoryPath, info.EntryName)),
                    true);
                try
                {
                    connection.DeleteDirectory(FtpPath.Combine(info.DirectoryPath, info.EntryName));
                }
                catch (Exception ex)
                {
                    abort = !process_error
                                (string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_DELETE_0),
                                    FtpPath.Combine(info.DirectoryPath, info.EntryName)),
                                ex);
                }
            }
            else
            {
                //remove one file
                main_window.NotifyLongOperation
                    (string.Format
                        (Options.GetLiteral(Options.LANG_DELETE_NOW_0),
                        FtpPath.Combine(info.DirectoryPath, info.EntryName)),
                    true);
                try
                {
                    connection.DeleteFile(FtpPath.Combine(info.DirectoryPath, info.EntryName));
                }
                catch (Exception ex)
                {
                    abort = !process_error
                                (string.Format
                                    (Options.GetLiteral(Options.LANG_CANNOT_DELETE_0),
                                    FtpPath.Combine(info.DirectoryPath, info.EntryName)),
                                ex);
                }
            }
        }