Example #1
0
        public void Supprimer(ITransfer transfer)
        {
            using (_monFtp = new Ftp())
            {
                _monFtp.Connect(_maConfig.Host, _maConfig.Port);
                _monFtp.Login(_maConfig.Login, _maConfig.MotDePass);

                string resteChemin = MethodesGlobales.GetCheminServerSansRacinne(transfer.GetPath(), _maConfig.GetUriChaine());

                if (string.IsNullOrEmpty(resteChemin))
                {
                    VariablesGlobales._leLog.LogCustom("Vous ne pouvez supprimer le répertoire racinne !");
                    MessageBox.Show("Vous ne pouvez supprimer le répertoire racinne !");
                }
                else
                {
                    if (transfer.EstUnDossier())
                    {
                        _monFtp.DeleteFolder(resteChemin);
                    }
                    else
                    {
                        _monFtp.DeleteFile(resteChemin);
                    }
                }

                _monFtp.Close();
            }
        }
Example #2
0
        public void DeleteFile(string InFileName)
        {
            Check.Require(!string.IsNullOrEmpty(InFileName));

            Ftp ftp = null;

            try
            {
                using (ftp = new Ftp())
                {
                    this.FTPConnect(ftp);

                    var remoteFilePath = Path.Combine(this.FolderPath, InFileName);
                    log.Info(string.Format("Deleting from [{0}]", remoteFilePath));
                    ftp.DeleteFile(InFileName);
                }
            }
            catch (Exception ex)
            {
                log.Error((string.Format("Failed deleting file [{0}] from [{1}]", InFileName)), ex);
                throw ex;
            }
            finally
            {
                if (ftp != null)
                {
                    ftp.Close();
                }
            }
        }
Example #3
0
        public void DownloadFiles(List <string> InFileNames, string InLocalDestinationFolderPath, bool InToDeleteOriginal)
        {
            Check.Require(InFileNames != null);
            Check.Require(!string.IsNullOrEmpty(InLocalDestinationFolderPath));

            Ftp ftp = null;

            try
            {
                using (ftp = new Ftp())
                {
                    this.FTPConnect(ftp);

                    foreach (var fileName in InFileNames)
                    {
                        try
                        {
                            var destinationFileNameFull = Path.Combine(InLocalDestinationFolderPath, fileName);
                            var remoteFilePath          = Path.Combine(this.FolderPath, fileName);

                            log.Info(string.Format("Downloading from [{0}] to [{1}]", remoteFilePath, destinationFileNameFull));

                            if (File.Exists(destinationFileNameFull)) //Clear the temp folder from previous attempts
                            {
                                File.Delete(destinationFileNameFull);
                            }

                            ftp.Download(fileName, destinationFileNameFull);
                            Check.Ensure(File.Exists(destinationFileNameFull), string.Format("File [{0}] should exist in [{1}]", fileName, InLocalDestinationFolderPath));

                            //Delete the original file if the file was copied to destination
                            if (InToDeleteOriginal)
                            {
                                try
                                {
                                    log.Info(string.Format("Deleting from [{0}]", remoteFilePath));
                                    ftp.DeleteFile(fileName);
                                }
                                catch (Exception ex)
                                {
                                    log.Error((string.Format("Failed deleting file [{0}]", remoteFilePath)), ex);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error((string.Format("Failed downloading file [{0}] to [{1}]", fileName, InLocalDestinationFolderPath)), ex);
                            throw ex;
                        }
                    }
                }
            }
            finally
            {
                if (ftp != null)
                {
                    ftp.Close();
                }
            }
        }
Example #4
0
        public override void Delete()
        {
            if (!Exists())
            {
                throw new FileNotFoundException();
            }

            Client.DeleteFile(Path.PathStr);
        }
        private void MoveFile(TextFile destFile)
        {
            using (var stream = new MemoryStream())
            {
                Client.Download(File.Path.PathStr, stream);
                destFile.Create(stream);
            }

            if (!KeepOriginal)
            {
                Client.DeleteFile(File.Path.PathStr);
            }
        }
        /// <summary>
        /// Deletes a file from FTP
        /// </summary>
        /// <param name="opts">The options</param>
        /// <returns>The result</returns>
        int FTPDeleteFile(FTPDeleteFileOptions opts)
        {
            using (Ftp ftp = new Ftp())
            {
                try
                {
                    ftp.Connect(Properties.Settings.Default.FTPServer);
                    ftp.Login(Properties.Settings.Default.FTPUsername, CommandLineSecurity.ToInsecureString(CommandLineSecurity.DecryptString(Properties.Settings.Default.FTPPassword)));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(new Form(), ex.Message, "Mist of Time Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(1);
                }

                try
                {
                    if (!ftp.FolderExists("cdn"))
                    {
                        ftp.CreateFolder("cdn");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(new Form(), ex.Message, "Mist of Time Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(1);
                }

                try
                {
                    if (!opts.ServerPath.StartsWith("/"))
                    {
                        opts.ServerPath = "/" + opts.ServerPath;
                    }
                    ftp.DeleteFile("cdn" + opts.ServerPath);
                }
                catch (Exception)
                {
                    return(2);
                }
            }

            return(0);
        }