Пример #1
0
        public override byte[] DownloadFileFromClusterByAbsolutePath(JobSpecification jobSpecification, string absoluteFilePath)
        {
            ConnectionInfo connection = _connectionPool.GetConnectionForUser(jobSpecification.ClusterUser);

            try
            {
                var client = new SftpClientAdapter((ExtendedSftpClient)connection.Connection);
                using var stream = new MemoryStream();
                var path = absoluteFilePath.Replace("~/", string.Empty).Replace("/~/", string.Empty);
                client.DownloadFile(path, stream);
                return(stream.ToArray());
            }
            finally
            {
                _connectionPool.ReturnConnection(connection);
            }
        }
Пример #2
0
        public override byte[] DownloadFileFromCluster(SubmittedJobInfo jobInfo, string relativeFilePath)
        {
            string         jobClusterDirectoryPath = FileSystemUtils.GetJobClusterDirectoryPath(_fileSystem.Cluster.LocalBasepath, jobInfo.Specification);
            ConnectionInfo connection = _connectionPool.GetConnectionForUser(jobInfo.Specification.ClusterUser);

            try
            {
                var client = new SftpClientAdapter((ExtendedSftpClient)connection.Connection);
                using MemoryStream stream = new MemoryStream();
                string file = jobClusterDirectoryPath + relativeFilePath;
                client.DownloadFile(file, stream);
                return(stream.ToArray());
            }
            finally
            {
                _connectionPool.ReturnConnection(connection);
            }
        }
Пример #3
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);
                    }
                }
            }
        }