Exemple #1
0
 internal FtpUploadTask(int intTask, FtpUploadService service, FtpConnectionModel ftpConnection, string pathLocal,
                        List <string> files, string pathRemote, FtpUploadService.UploadMode mode)
 {
     _taskId        = intTask;
     _service       = service;
     _ftpConnection = ftpConnection;
     _pathLocal     = pathLocal;
     _files         = files;
     _pathRemote    = pathRemote;
     _mode          = mode;
 }
Exemple #2
0
        /// <summary>
        ///		Comprueba si se debe subir un archivo
        /// </summary>
        private bool MustUpload(string file, IList <FtpEntry> remoteFiles, FtpUploadService.UploadMode mode)
        {
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);

            // Comprueba si ya existe un archivo remoto con el mismo tamaño
            if (mode == FtpUploadService.UploadMode.CheckSize)
            {
                foreach (FtpEntry remoteFile in remoteFiles)
                {
                    if (fileInfo.Name.Equals(remoteFile.Name, StringComparison.CurrentCultureIgnoreCase) &&
                        fileInfo.Length == remoteFile.Size)
                    {
                        return(false);
                    }
                }
            }
            // Si ha llegado hasta aquí es porque se debe subir el archivo
            return(true);
        }
        /// <summary>
        ///		Procesa la subida de archivos
        /// </summary>
        internal void Process(string ftpConnection, string localPath, string remotePath, int process, FtpUploadService.UploadMode mode)
        {
            Model.Connections.FtpConnectionModel connection = SearchConnection(ftpConnection);

            if (connection == null)
            {
                ShowLog("Error en la subida de archivos", $"No se encuentra la conexión '{ftpConnection}'", true);
            }
            else if (localPath.IsEmpty())
            {
                ShowLog("Error en la subida de archivos", "No se ha recibido ningún valor para el directorio local", true);
            }
            else if (!System.IO.Directory.Exists(localPath) && !System.IO.File.Exists(localPath))
            {
                ShowLog("Error en la subida de archivos", $"No se encuentra el directorio local {localPath}", true);
            }
            else if (remotePath.IsEmpty())
            {
                ShowLog("Error en la subida de archivos", "No se ha recibido ningún valor para el directorio remoto", true);
            }
            else
            {
                FtpUploadService ftpUpload = new FtpUploadService();

                // Asigna los manejadores de eventos
                ftpUpload.ProgressMessage += (sender, evntArgs) =>
                {
                    FtpManagerViewModel.Instance.HostController.Messenger.SendProgress($"Upload_{evntArgs.TaskId}",
                                                                                       FtpManagerViewModel.Instance.ModuleName,
                                                                                       $"Subir archivos - Tarea {evntArgs.TaskId}",
                                                                                       evntArgs.Message, evntArgs.Progress,
                                                                                       evntArgs.Maximum, null);
                };
                // Comienza el proceso
                ftpUpload.Upload(connection, localPath, remotePath, process, mode);
                // Log
                ShowLog("Proceso de subida de archivos", "Fin del proceso", false);
            }
        }