public void AppendFileToFolderShouldHaveFullPath()
        {
            FtpPath fileSystemItem =
                new FtpPath("/a", FileSystemType.Directory).Append(new FtpPath("/b/c.txt", FileSystemType.File));

            Assert.Equal("/a/b/c.txt", fileSystemItem.Path);
        }
Example #2
0
 public void Recive(string fromServPath, string toLocalPath, string fileEnding)
 {
     using (var ftpClient = new FtpClient(ftpUri, ftpCredentials))
     {
         var files = ftpClient.ListEntries(fromServPath);
         foreach (var file in files)
         {
             if (file.Type != FtpEntryType.File)
             {
                 continue;
             }
             if (!file.Name.EndsWith(fileEnding))
             {
                 continue;
             }
             FtpPath path = new FtpPath(fromServPath + "/" + file.Name);
             using (var stream = ftpClient.Retr(path, FtpTransferMode.Binary))
             {
                 using (var fileStream = new FileStream(toLocalPath + "/" + file.Name, FileMode.Create, FileAccess.Write))
                 {
                     stream.CopyTo(fileStream);
                 }
             }
             ftpClient.RnfrTo(fromServPath + "/" + file.Name, fromServPath + "/" + file.Name + ".BACKUP." + Guid.NewGuid() + ".txt");
             //ftpClient.Dele(fromServPath + "/" + file.Name);
         }
     }
 }
Example #3
0
 internal FtpAbstractStreamCommand(FtpConnection connection, FtpPath path,
                                   FtpClient.FtpTransferMode mode = FtpClient.FtpTransferMode.Binary)
     : base(connection)
 {
     Path = path;
     Mode = mode;
 }
Example #4
0
        /// <summary>
        /// Parses the line.
        /// </summary>
        /// <param name="directoryLine">The directory line.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        /* test */
        internal static FtpEntry ParseUnix(string directoryLine, FtpPath parent)
        {
            var match = UnixListEx.Match(directoryLine);
            if (!match.Success)
                return null;

            var literalType = match.Groups["xtype"].Value;
            var name = match.Groups["name"].Value;
            var type = FtpEntryType.File;
            string target = null;
            if (string.Equals(literalType, "d", StringComparison.InvariantCultureIgnoreCase))
                type = FtpEntryType.Directory;
            else if (string.Equals(literalType, "l", StringComparison.InvariantCultureIgnoreCase))
            {
                type = FtpEntryType.Link;
                const string separator = " -> ";
                var linkIndex = name.IndexOf(separator, StringComparison.InvariantCultureIgnoreCase);
                if (linkIndex >= 0)
                {
                    target = name.Substring(linkIndex + separator.Length);
                    name = name.Substring(0, linkIndex);
                }
            }
            var ftpEntry = new FtpEntry(parent, name, long.Parse(match.Groups["size"].Value), type, ParseDateTime(match, DateTime.Now), target);
            return ftpEntry;
        }
Example #5
0
        private Task SynchronizeFileAsync(LocalFile localFile, FtpPath parentPath, FtpListItem remote)
        {
            if (remote == null)
            {
                Log(localFile.Depth, ItemAction.Add, localFile.Name);
                return(PushFileAsync(localFile));
            }

            if (remote.Type == FtpFileSystemObjectType.Directory)
            {
                DeleteFtpDirectory(parentPath.GetChildPath(remote.Name));
                Log(localFile.Depth, ItemAction.Replace, localFile.Name);
                return(PushFileAsync(localFile));
            }

            if (remote.Type == FtpFileSystemObjectType.Link)
            {
                Log(localFile.Depth, ItemAction.Replace, localFile.Name, "remote is a link");
                return(PushFileAsync(localFile));
            }

            if (remote.Modified.ToLocalTime().TruncateToMinutes() != localFile.LastWriteTime.TruncateToMinutes())
            {
                Log(localFile.Depth, ItemAction.Replace, localFile.Name);
                return(PushFileAsync(localFile));
            }

            Log(localFile.Depth, ItemAction.Skip, localFile.Name);
            return(null); // I know it's bad style, but it optimizes the collection/wait for a common case when everything is up to date
        }
Example #6
0
        public Task UploadFileAsync(
            [NotNull] FtpPath filePath,
            [NotNull] FileInfo sourceFile,
            CancellationToken cancellationToken = default)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (sourceFile == null)
            {
                throw new ArgumentNullException(nameof(sourceFile));
            }

            if (filePath.Type != FileSystemType.File)
            {
                throw new ArgumentException($"The ftp upload path '{filePath.Path}' is not a file");
            }

            if (!sourceFile.Exists)
            {
                throw new FtpException($"Source file '{sourceFile.FullName}' does not exist");
            }

            return(UploadFileInternalAsync(filePath, sourceFile, cancellationToken));
        }
Example #7
0
        private async Task UploadFileInternalAsync(
            [NotNull] FtpPath filePath,
            [NotNull] FileInfo sourceFile,
            CancellationToken cancellationToken = default)
        {
            _logger.Debug("Settings file content upload length to {Length} bytes for file '{Path}'",
                          sourceFile.Length,
                          filePath.Path);

            var progress = GetProgressAction();

            try
            {
                await _ftpClient.UploadFileAsync(sourceFile.FullName,
                                                 filePath.Path,
                                                 FtpRemoteExists.Overwrite,
                                                 true,
                                                 FtpVerify.Delete | FtpVerify.Retry,
                                                 progress,
                                                 cancellationToken);

                _logger.Verbose("Uploaded {SourceFile} to {TargetFile}", sourceFile.FullName, filePath.Path);
            }
            catch (Exception ex)
            {
                throw new FtpException(
                          $"Could not copy source file '{sourceFile.FullName}' to path '{filePath.Path}' stream",
                          ex);
            }
        }
Example #8
0
        /// <summary>
        /// Parses the line.
        /// </summary>
        /// <param name="directoryLine">The directory line.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        internal /* test */ static FtpEntry ParseLine(string directoryLine, FtpPath parent)
        {
            var match = WindowsListEx.Match(directoryLine);

            if (!match.Success)
            {
                return(null);
            }

            var  name        = match.Groups["name"].Value;
            var  date        = ParseDateTime(match, DateTime.Now);
            var  literalSize = match.Groups["size"].Value;
            long?size        = null;
            var  type        = FtpEntryType.File;

            if (!string.IsNullOrEmpty(literalSize))
            {
                size = long.Parse(literalSize);
            }
            else
            {
                type = FtpEntryType.Directory;
            }
            return(new FtpEntry(parent, name, size, type, date, null));
        }
Example #9
0
        private async Task <FtpSummary> UploadDirectoryInternalAsync(
            [NotNull] DirectoryInfo sourceDirectory,
            [NotNull] DirectoryInfo baseDirectory,
            FtpPath basePath,
            CancellationToken cancellationToken)
        {
            var dir = basePath.Append(new FtpPath(PathHelper.RelativePath(sourceDirectory, baseDirectory),
                                                  FileSystemType.Directory));

            var summary = new FtpSummary();

            bool directoryExists = await DirectoryExistsAsync(dir, cancellationToken);

            if (!directoryExists)
            {
                await CreateDirectoryAsync(dir, cancellationToken);

                summary.CreatedDirectories.Add(dir.Path);
            }

            var uploadSummary = await UploadFilesAsync(sourceDirectory, baseDirectory, basePath, cancellationToken);

            summary.Add(uploadSummary);

            return(summary);
        }
Example #10
0
        private async Task DeleteFileInternalAsync([NotNull] FtpPath filePath, CancellationToken cancellationToken)
        {
            int       attempt     = 1;
            const int MaxAttempts = 5;

            while (true)
            {
                try
                {
                    await _ftpClient.DeleteFileAsync(filePath.Path, cancellationToken);

                    _logger.Verbose("Delete file {FilePath}", filePath.Path);

                    return;
                }
                catch (Exception ex)
                {
                    if (attempt > MaxAttempts)
                    {
                        throw new FtpException($"Could not delete file '{filePath.Path}'", ex);
                    }

                    if (!await _ftpClient.FileExistsAsync(filePath.Path, cancellationToken))
                    {
                        _logger.Verbose(ex, "Could not delete file because it does not exists");
                        return;
                    }

                    attempt++;
                    _logger.Verbose(ex, "FPT Error, retrying");
                    await Task.Delay(TimeSpan.FromMilliseconds(attempt * 50), cancellationToken);
                }
            }
        }
        /// <summary>
        ///		Interpreta la línea
        /// </summary>
        protected override FtpEntry ParseLine(string pathLine, FtpPath pathParent)
        {
            FtpEntry entry = null;
            Match    match = RegExWindows.Match(pathLine);

            // Interpreta la línea
            if (match.Success)
            {
                string   name              = match.Groups["name"].Value;
                DateTime createdAt         = ParseDateTime(match);
                string   strLiteralSize    = match.Groups["size"].Value;
                long     size              = 0;
                FtpEntry.FtpEntryType type = FtpEntry.FtpEntryType.File;

                // Obtiene el tamaño del archivo. Si no tiene tamaño, se le considera un directorio
                if (!string.IsNullOrEmpty(strLiteralSize))
                {
                    size = long.Parse(strLiteralSize);
                }
                else
                {
                    type = FtpEntry.FtpEntryType.Directory;
                }
                // Obtine la entrada
                entry = new FtpEntry(pathParent, name, size, type, createdAt, null);
            }
            // Devuelve la entrada
            return(entry);
        }
Example #12
0
        /// <summary>
        ///		Interpreta una línea en formato Unix
        /// </summary>
        protected virtual FtpEntry ParseLine(string pathLine, FtpPath pathParent)
        {
            FtpEntry entry = null;
            Match    match = RegExUnix.Match(pathLine);

            // Obtiene los datos de la línea
            if (match.Success)
            {
                string extendedType        = match.Groups["xtype"].Value;
                string name                = match.Groups["name"].Value;
                FtpEntry.FtpEntryType type = FtpEntry.FtpEntryType.File;
                string target              = null;

                // Obtiene los datos de la entrada
                if (string.Equals(extendedType, "d", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = FtpEntry.FtpEntryType.Directory;
                }
                else if (string.Equals(extendedType, "l", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Indica que es un vínculo
                    type = FtpEntry.FtpEntryType.Link;
                    // Separa el nombre del vínculo
                    SepareLink(ref name, ref target);
                }
                // Crea el objeto con los datos de la entrada
                entry = new FtpEntry(pathParent, name, long.Parse(match.Groups["size"].Value), type,
                                     ParseDateTime(match), target);
            }
            // Devuelve la entrada del directorio
            return(entry);
        }
        public Task <DeploySummary> UploadDirectoryAsync(
            RuleConfiguration ruleConfiguration,
            DirectoryInfo sourceDirectory,
            DirectoryInfo baseDirectory,
            FtpPath basePath,
            CancellationToken cancellationToken)
        {
            if (ruleConfiguration is null)
            {
                throw new ArgumentNullException(nameof(ruleConfiguration));
            }

            if (sourceDirectory is null)
            {
                throw new ArgumentNullException(nameof(sourceDirectory));
            }

            if (baseDirectory is null)
            {
                throw new ArgumentNullException(nameof(baseDirectory));
            }

            if (basePath is null)
            {
                throw new ArgumentNullException(nameof(basePath));
            }

            return(UploadDirectoryInternalAsync(sourceDirectory, baseDirectory, basePath, cancellationToken));
        }
Example #14
0
        private bool DeleteFtpDirectory(FtpPath path)
        {
            Log(path.Depth, ItemAction.Delete, path.Name);
            var parentWorkingDirectory = _remoteWorkingDirectory;
            var itemsRemain            = false;

            foreach (var child in _mainClient.GetListing(path.Name, FtpListOption.AllFiles))
            {
                var childPath = path.GetChildPath(child.Name);
                var exclude   = MatchExcludes(childPath.Relative);
                if (exclude != null)
                {
                    Log(path.Depth + 1, ItemAction.Skip, child.Name, $"excluded ({exclude.Original})");
                    itemsRemain = true;
                    continue;
                }

                EnsureRemoteWorkingDirectory(path.Absolute);
                if (!DeleteFtpAny(childPath, child.Type))
                {
                    itemsRemain = true;
                }
            }
            EnsureRemoteWorkingDirectory(parentWorkingDirectory);
            if (itemsRemain)
            {
                Log(path.Depth + 1, ItemAction.Skip, $"# dir '{path.Name}' not deleted (items remain)");
                return(false);
            }
            FtpRetry.ConnectedCall(_mainClient, parentWorkingDirectory, c => c.DeleteDirectory(path.Name));
            return(true);
        }
Example #15
0
        private void PushDirectory(LocalDirectory localDirectory, FtpPath ftpParentPath)
        {
            var ftpPath = ftpParentPath.GetChildPath(localDirectory.Name);

            FtpRetry.ConnectedCall(_mainClient, ftpParentPath.Absolute, c => c.CreateDirectory(localDirectory.Name));
            PushDirectoryContents(localDirectory, ftpPath);
        }
Example #16
0
        /// <summary>
        /// Parses the line.
        /// </summary>
        /// <param name="directoryLine">The directory line.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        internal /* test */ static FtpEntry ParseUnix(string directoryLine, FtpPath parent)
        {
            var match = UnixListEx.Match(directoryLine);

            if (!match.Success)
            {
                return(null);
            }

            var    literalType = match.Groups["xtype"].Value;
            var    name        = match.Groups["name"].Value;
            var    type        = FtpEntryType.File;
            string target      = null;

            if (string.Equals(literalType, "d", StringComparison.InvariantCultureIgnoreCase))
            {
                type = FtpEntryType.Directory;
            }
            else if (string.Equals(literalType, "l", StringComparison.InvariantCultureIgnoreCase))
            {
                type = FtpEntryType.Link;
                const string separator = " -> ";
                var          linkIndex = name.IndexOf(separator, StringComparison.InvariantCultureIgnoreCase);
                if (linkIndex >= 0)
                {
                    target = name.Substring(linkIndex + separator.Length);
                    name   = name.Substring(0, linkIndex);
                }
            }
            var ftpEntry = new FtpEntry(parent, name, long.Parse(match.Groups["size"].Value), type, ParseDateTime(match, DateTime.Now), target);

            return(ftpEntry);
        }
Example #17
0
        public Task <FtpSummary> UploadDirectoryAsync(
            [NotNull] RuleConfiguration ruleConfiguration,
            [NotNull] DirectoryInfo sourceDirectory,
            [NotNull] DirectoryInfo baseDirectory,
            [NotNull] FtpPath basePath,
            CancellationToken cancellationToken)
        {
            if (ruleConfiguration == null)
            {
                throw new ArgumentNullException(nameof(ruleConfiguration));
            }

            if (sourceDirectory == null)
            {
                throw new ArgumentNullException(nameof(sourceDirectory));
            }

            if (baseDirectory == null)
            {
                throw new ArgumentNullException(nameof(baseDirectory));
            }

            if (basePath == null)
            {
                throw new ArgumentNullException(nameof(basePath));
            }

            return(UploadDirectoryInternalAsync(sourceDirectory, baseDirectory, basePath, cancellationToken));
        }
Example #18
0
        private static async Task <bool> _monitorArchive(FtpFile f, FtpPath p, CancellationToken ct)
        {
            var sw = new Stopwatch();

            sw.Start();
            await logger.Log($"Обрабатываю архив {f.Name} по пути {p.Path}");

            var sw1 = new Stopwatch();

            sw1.Start();
            var allEntriesInArchive = FtpClient.Get(logger).GetArchiveEntries(p.Path + f.Name, p.Login, p.Password);
            await logger.Log($"Архив получен {sw1.Elapsed}");

            sw1.Restart();
            new ZipHelper().ParseArchve(f, allEntriesInArchive);
            await logger.Log($"Дерево файлов построено {sw1.Elapsed}");

            sw1.Restart();
            var data = JsonConvert.SerializeObject(f);
            await logger.Log($"Дерево файлов сериализовано {sw1.Elapsed}, отправляю на сервер");

            sw1.Restart();
            var res = await apiDataProvider.SendFileTreeAsync(new StringContent(data, Encoding.UTF8, MediaTypeNames.Application.Json), p.Id, ct);

            await logger.Log($"Дерево файлов отправлено на сервер {sw1.Elapsed}");

            sw1.Stop();
            await logger.Log($"Архив {f.Name} обработан ОБЩЕЕ ВРЕМЯ АРХИВА: {sw.Elapsed}");

            sw.Stop();

            return(true);
        }
        public UpdateDeploymentTarget(
            DeploymentTargetId id,
            bool allowExplicitPreRelease,
            string?url,
            string packageId,
            string?iisSiteName          = null,
            string?nugetPackageSource   = null,
            string?nugetConfigFile      = null,
            bool autoDeployEnabled      = false,
            string?publishSettingsXml   = null,
            string?targetDirectory      = null,
            string?webConfigTransform   = null,
            string?excludedFilePatterns = null,
            string?environmentTypeId    = null,
            string?packageListTimeout   = null,
            string?publishType          = null,
            string?ftpPath                  = null,
            string?metadataTimeout          = default,
            bool requireEnvironmentConfig   = default,
            string?environmentConfiguration = null,
            bool packageListPrefixEnabled   = false,
            string?packageListPrefix        = null)
        {
            Id = id;
            AllowExplicitPreRelease = allowExplicitPreRelease;
            Uri.TryCreate(url, UriKind.Absolute, out var uri);
            Url                  = uri;
            PackageId            = packageId?.Trim();
            ExcludedFilePatterns = excludedFilePatterns;
            PublishType.TryParseOrDefault(publishType, out var foundPublishType);
            FtpPath.TryParse(ftpPath, FileSystemType.Directory, out var path);
            PublishType        = foundPublishType ?? PublishType.Default;
            FtpPath            = path;
            IisSiteName        = iisSiteName;
            NugetPackageSource = nugetPackageSource;
            NugetConfigFile    = nugetConfigFile;
            AutoDeployEnabled  = autoDeployEnabled;
            PublishSettingsXml = publishSettingsXml;
            TargetDirectory    = targetDirectory;
            WebConfigTransform = webConfigTransform;
            IsValid            = Id != DeploymentTargetId.Invalid;
            EnvironmentTypeId  = environmentTypeId?.Trim();
            PackageListPrefix  = packageListPrefix;

            if (TimeSpan.TryParse(packageListTimeout, out var timeout) && timeout.TotalSeconds > 0.5D)
            {
                PackageListTimeout = timeout;
            }

            if (TimeSpan.TryParse(metadataTimeout, out var parsedMetadataTimeout) &&
                parsedMetadataTimeout.TotalSeconds > 0.5D)
            {
                MetadataTimeout = parsedMetadataTimeout;
            }

            RequireEnvironmentConfig = requireEnvironmentConfig;
            EnvironmentConfiguration = environmentConfiguration;
            PackageListPrefixEnabled = packageListPrefixEnabled;
        }
Example #20
0
 public ManagerFtp(string ftpUri, bool isPassive, int timeoutSec, Logger logger)
 {
     this.FTPUri     = new Uri(ftpUri);
     this.FtpPath    = new FtpPath(SettingsContainer.GetSettings().FtpFolder);
     this.isPassive  = isPassive;
     this.logger     = logger;
     this.wBService  = new WBService(logger);
     this.timeoutSec = timeoutSec;
 }
Example #21
0
        public override void ExecuteCommand(FtpSession session, StringRequestInfo requestInfo)
        {
            if (!session.Logged)
            {
                session.Send(FtpCoreResource.AuthenticationFailed_530);
                return;
            }

            if (!string.IsNullOrEmpty(requestInfo.Body))
            {
                if (requestInfo.Body.StartsWith(FtpPath.Root))
                {
                    session.Context.CurrentPath = requestInfo.Body;
                }
                else
                {
                    session.Context.CurrentPath = FtpPath.Combine(session.Context.CurrentPath, requestInfo.Body);
                }
            }

            List <ListItem> list = session.AppServer.FtpServiceProvider.GetList(session.Context);

            if (session.Context.Status == FtpStatus.Error)
            {
                session.Send(session.Context.Message);
                return;
            }

            DataConnection dataConn = session.DataConnection;

            if (dataConn != null && dataConn.RunDataConnection().Wait(60 * 1000))
            {
                session.Send(FtpCoreResource.DataConnectionAccepted_150);

                try
                {
                    dataConn.SendResponse(session.Context, list);
                }
                catch (Exception e)
                {
                    session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
                    session.Logger.Error(e);
                    return;
                }
                finally
                {
                    session.CloseDataConnection();
                }

                session.Send(FtpCoreResource.DataTransferComplete_226);
            }
            else
            {
                session.CloseDataConnection();
                session.Send(FtpCoreResource.DataConnectionCannotOpen_420);
            }
        }
        public DeploymentExecutionDefinition(
            string packageId,
            string targetDirectoryPath,
            MayBe <SemanticVersion> semanticVersion,
            string nuGetConfigFile    = null,
            string nuGetPackageSource = null,
            string iisSiteName        = null,
            bool isPreRelease         = false,
            bool force = false,
            string environmentConfig   = null,
            string publishSettingsFile = null,
            Dictionary <string, string[]> parameters = null,
            string excludedFilePatterns   = null,
            bool requireEnvironmentConfig = false,
            string webConfigTransformFile = null,
            string publishType            = null,
            string ftpPath                = null,
            string nugetExePath           = null,
            string packageListPrefix      = null,
            bool?packageListPrefixEnabled = null)
        {
            SemanticVersion = semanticVersion ?? MayBe <SemanticVersion> .Nothing;
            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(nameof(packageId));
            }

            ExcludedFilePatterns = excludedFilePatterns?.Split(';').ToImmutableArray() ?? ImmutableArray <string> .Empty;

            PackageId           = packageId;
            TargetDirectoryPath = targetDirectoryPath;
            NuGetConfigFile     = nuGetConfigFile;
            NuGetPackageSource  = nuGetPackageSource;
            IisSiteName         = iisSiteName;
            IsPreRelease        = SemanticVersion?.IsPrerelease ?? isPreRelease;
            Force                    = force;
            EnvironmentConfig        = environmentConfig;
            PublishSettingsFile      = publishSettingsFile;
            RequireEnvironmentConfig = requireEnvironmentConfig;
            WebConfigTransformFile   = webConfigTransformFile;
            Parameters               = parameters?.ToDictionary(pair => pair.Key,
                                                                pair => new StringValues(pair.Value ?? Array.Empty <string>()))
                                       .ToImmutableDictionary() ??
                                       ImmutableDictionary <string, StringValues> .Empty;

            _       = PublishType.TryParseOrDefault(publishType, out PublishType publishTypeValue);
            _       = FtpPath.TryParse(ftpPath, FileSystemType.Directory, out FtpPath path);
            FtpPath = path;

            PublishType = publishTypeValue;

            ExcludedFilePatternsCombined = excludedFilePatterns;

            NuGetExePath             = nugetExePath;
            PackageListPrefix        = packageListPrefix;
            PackageListPrefixEnabled = packageListPrefixEnabled;
        }
Example #23
0
        public Task <bool> FileExistsAsync([NotNull] FtpPath filePath, CancellationToken cancellationToken)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            return(FileExistsInternalAsync(filePath, cancellationToken));
        }
Example #24
0
        public Task <ImmutableArray <FtpPath> > ListDirectoryAsync(
            [NotNull] FtpPath path,
            CancellationToken cancellationToken = default)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(ListDirectoryInternalAsync(path, cancellationToken));
        }
Example #25
0
 private bool DeleteFtpAny(FtpPath path, FtpFileSystemObjectType type)
 {
     if (type == FtpFileSystemObjectType.Directory)
     {
         return(DeleteFtpDirectory(path));
     }
     else
     {
         DeleteFtpFile(path);
         return(true);
     }
 }
Example #26
0
        private Task PushAnyAsync(LocalItem local, FtpPath ftpParentPath)
        {
            var directory = local as LocalDirectory;

            if (directory != null)
            {
                PushDirectory(directory, ftpParentPath);
                return(Done);
            }

            return(PushFileAsync((LocalFile)local));
        }
 public FtpPath(FtpPath currentPath, FtpFile file)
 {
     File = file;
     if (currentPath.Path.EndsWith("/"))
     {
         Path = currentPath + file.Name;
     }
     else
     {
         Path = currentPath.Path + "/" + file.Name;
     }
 }
Example #28
0
        private async Task DeleteDirectoryInternalAsync([NotNull] FtpPath path, CancellationToken cancellationToken)
        {
            try
            {
                await _ftpClient.DeleteDirectoryAsync(path.Path, FtpListOption.Recursive, cancellationToken);

                _logger.Verbose("Deleted directory {Path}", path.Path);
            }
            catch (Exception ex)
            {
                throw new FtpException($"Could not delete directory '{path.Path}'", ex);
            }
        }
Example #29
0
 private async Task CreateDirectoryInternalAsync(
     [NotNull] FtpPath directoryPath,
     CancellationToken cancellationToken)
 {
     try
     {
         await _ftpClient.CreateDirectoryAsync(directoryPath.Path, cancellationToken);
     }
     catch (Exception ex) when(!ex.IsFatal())
     {
         throw new FtpException($"Could not created directory {directoryPath}", ex);
     }
 }
Example #30
0
        public Task DeleteFileAsync([NotNull] FtpPath filePath, CancellationToken cancellationToken)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (filePath.Type != FileSystemType.File)
            {
                throw new ArgumentException($"The ftp delete path '{filePath.Path}' is not a file");
            }

            return(DeleteFileInternalAsync(filePath, cancellationToken));
        }
Example #31
0
        public Task CreateDirectoryAsync([NotNull] FtpPath directoryPath, CancellationToken cancellationToken)
        {
            if (directoryPath == null)
            {
                throw new ArgumentNullException(nameof(directoryPath));
            }

            if (directoryPath.Type != FileSystemType.Directory)
            {
                throw new ArgumentException($"The ftp create path {directoryPath.Path} is not a directory");
            }

            return(CreateDirectoryInternalAsync(directoryPath, cancellationToken));
        }
        public Task DeleteDirectoryAsync(FtpPath path, CancellationToken cancellationToken)
        {
            if (path is null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (path.Type != FileSystemType.Directory)
            {
                throw new ArgumentException($"The ftp delete path {path.Path} is not a directory");
            }

            return(DeleteDirectoryInternalAsync(path, cancellationToken));
        }
Example #33
0
        /// <summary>
        /// Parses the line.
        /// </summary>
        /// <param name="directoryLine">The directory line.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        /* test */
        internal static FtpEntry ParseLine(string directoryLine, FtpPath parent)
        {
            var match = WindowsListEx.Match(directoryLine);
            if (!match.Success)
                return null;

            var name = match.Groups["name"].Value;
            var date = ParseDateTime(match, DateTime.Now);
            var literalSize = match.Groups["size"].Value;
            long? size = null;
            var type = FtpEntryType.File;
            if (!string.IsNullOrEmpty(literalSize))
                size = long.Parse(literalSize);
            else
                type = FtpEntryType.Directory;
            return new FtpEntry(parent, name, size, type, date, null);
        }
Example #34
0
 /// <summary>
 /// Parses Windows formatted list line.
 /// </summary>
 /// <param name="directoryLine">The directory line.</param>
 /// <param name="parent">The parent.</param>
 /// <returns></returns>
 public override FtpEntry Parse(string directoryLine, FtpPath parent)
 {
     return ParseLine(directoryLine, parent);
 }
Example #35
0
 /// <summary>
 /// Parses the specified directory line.
 /// </summary>
 /// <param name="directoryLine">The directory line.</param>
 /// <param name="parent">The parent.</param>
 /// <returns></returns>
 public virtual FtpEntry Parse(string directoryLine, FtpPath parent)
 {
     return ParseUnix(directoryLine, parent);
 }