private void ProcessAckFile(string folderName, string fileName, IUserConfiguration user, IFtpHelper ftpHelper)
        {
            string ftpFileName   = $@"{folderName}/{fileName}";
            string localFileName = $@"{new FilePathHelper(_configuration, user.Name).GetReportsFilesFolder()}\{fileName}";

            _logger.Debug($"Process ack file {ftpFileName}");

            ftpHelper.DownloadFile(ftpFileName, localFileName);

            if (File.Exists(localFileName))
            {
                if (user.HasDeleteFtp)
                {
                    ftpHelper.DeleteFile(ftpFileName);
                }

                try
                {
                    _logger.Debug($"Delete local file {fileName}");

                    File.Delete(localFileName);
                }
                catch (Exception e)
                {
                    _logger.Error($"Error trying to delete file {localFileName} -- {e}");
                }
            }
        }
        private bool GetFileFromFTP(string file, IUserConfiguration user, IFtpHelper ftpHelper, ProcessResult result)
        {
            var filePathHelper = new FilePathHelper(_configuration, user.Name);

            string localFileName;

            if (!ValidateFile(file, filePathHelper, result, out localFileName))
            {
                return(false);
            }

            _logger.Debug($"Start to download {file} for user {user.Name}");

            bool downloadResult = ftpHelper.DownloadFile(file, localFileName);

            if (downloadResult && File.Exists(localFileName))
            {
                if (Path.GetExtension(file).Equals(".zip", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (UnzipFile(localFileName, filePathHelper.GetDownloadsFolder()) == 0)
                    {
                        string message = $"{DateTime.UtcNow}:Problems to unzip the file {file}.";
                        result.Type = ResulType.UNZIP;
                        result.WriteError(message);
                        return(false);
                    }

                    try
                    {
                        File.Delete(localFileName); // Delete zip file
                    }
                    catch { }
                }
                else
                {
                    string newFileName = localFileName.Replace(".downloading", ".processing");

                    File.Move(localFileName, newFileName);
                }
            }
            else
            {
                string message = $"{DateTime.UtcNow}:Problems to download the file {file}.";
                result.Type = ResulType.DOWNLOAD;
                result.WriteError(message);
                _logger.Error($"Download problems with file {file}.");

                try
                {
                    // Delete wrong file to retry.
                    File.Delete(localFileName);
                }
                catch { }

                return(false);
            }

            return(true);
        }