예제 #1
0
        private ICollection <FileInformation> ListChangedFilesInDirectory(string rootDirectory, string currentDirectory, DateTime?lastModificationLimit, ClusterAuthenticationCredentials credentials, SftpClientAdapter client)
        {
            List <FileInformation> results = new List <FileInformation>();

            foreach (SftpFile file in client.ListDirectory(currentDirectory))
            {
                if (file.Name == "." || file.Name == "..")
                {
                    continue;
                }

                if (file.IsDirectory)
                {
                    results.AddRange(ListChangedFilesInDirectory(rootDirectory, FileSystemUtils.ConcatenatePaths(currentDirectory, file.Name), lastModificationLimit, credentials, client));
                }
                else if (((!lastModificationLimit.HasValue) || (lastModificationLimit.Value <= file.LastWriteTime)))
                {
                    results.Add(new FileInformation
                    {
                        FileName         = file.FullName.Replace(rootDirectory, string.Empty),
                        LastModifiedDate = file.LastWriteTime
                    });
                }
            }
            return(results);
        }
예제 #2
0
        private void CopyAllFromSftp(string source, string target, bool overwrite, DateTime?lastModificationLimit, SftpClientAdapter client, string[] excludedFiles)
        {
            string sourcePath = source;

            if (!Directory.Exists(target))
            {
                Directory.CreateDirectory(target);
            }

            foreach (SftpFile file in client.ListDirectory(sourcePath))
            {
                if (file.Name == "." || file.Name == "..")
                {
                    continue;
                }

                if (file.IsDirectory)
                {
                    CopyAllFromSftp(FileSystemUtils.ConcatenatePaths(source, file.Name), Path.Combine(target, file.Name), overwrite,
                                    lastModificationLimit, client, FileSystemUtils.GetExcludedFilesForSubdirectory(excludedFiles, file.Name));
                }
                else
                {
                    if (excludedFiles != null && excludedFiles.Contains(file.Name))
                    {
                        continue;
                    }

                    string targetFilePath = Path.Combine(target, file.Name);
                    if (((!File.Exists(targetFilePath)) || overwrite) &&
                        ((!lastModificationLimit.HasValue) || (lastModificationLimit.Value < file.LastWriteTime)))
                    {
                        using FileStream targetStream = new FileStream(targetFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
                        client.DownloadFile(file.FullName, targetStream);
                    }
                }
            }
        }
예제 #3
0
        private void DeleteRemoteDirectory(string remotePath, SftpClientAdapter client)
        {
            _logger.LogDebug($"Starting delete remote directory {remotePath}");
            if (client.Exists(remotePath))
            {
                foreach (SftpFile file in client.ListDirectory(remotePath))
                {
                    if (file.Name == "." || file.Name == "..")
                    {
                        continue;
                    }

                    if (file.IsSymbolicLink)
                    {
                        _logger.LogDebug($"Deleting symlink {file.Name}");
                        client.Delete(file.FullName);
                    }
                    else
                    {
                        if (file.IsDirectory)
                        {
                            _logger.LogDebug($"Deleting subdirectory {file.Name}");
                            DeleteRemoteDirectory(file.FullName, client);
                        }
                        else
                        {
                            _logger.LogDebug($"Deleting file {file.Name}");
                            client.DeleteFile(file.FullName);
                        }
                    }
                }

                _logger.LogDebug($"Deleting root directory {remotePath}");
                client.DeleteDirectory(remotePath);
            }
        }