Beispiel #1
0
        /// <summary>
        /// Downloads a directory
        /// </summary>
        /// <param name="client">The Sftp client</param>
        /// <param name="file">The directory used to download its files</param>
        /// <param name="filter">The download filter</param>
        /// <param name="silentDownload">Download the files without listing everything</param>
        public static void Download(this RenciSftpClient client, SiteCredentials credentials,
                                    MappedPath dir, SftpFilter filter, Boolean replace, Boolean silentDownload = false)
        {
            var      files = SftpUtils.ListFiles(client, dir.GetFullRemotePath(), filter, silentDownload);
            string   fileName, serverCopy;
            FileInfo cC, wC;

            AuraSftpClient.SSHTransactionVoid(credentials, (Action <AuraSftpClient>)((AuraSftpClient c) => {
                foreach (String remoteFile in files)
                {
                    fileName   = remoteFile.Replace((string)dir.GetFullRemotePath(), "").Substring(1).Replace("/", "\\");
                    serverCopy = Path.Combine((string)dir.GetFullServerCopy(), fileName);
                    //Cache copy
                    cC = new FileInfo(serverCopy);
                    //The path to the working copy
                    wC = new FileInfo(Path.Combine((string)dir.GetFullProjectCopy(), fileName));
                    DownloadFile(c, remoteFile, cC, wC, replace, silentDownload);
                }
            }));
        }
Beispiel #2
0
 /// <summary>
 /// Pull the files from the server that are defined on the project
 /// configuration file Map
 /// </summary>
 /// <param name="prj">The current project</param>
 /// <param name="replace">True if the pulled files will remove the local ones</param>
 /// <param name="silentDownload">Download the files without listing everything</param>
 private void PullFromServer(Project prj, Boolean replace, Boolean silentDownload = false)
 {
     if (prj.Data.Map.Files.Count() > 0 || prj.Data.Map.Directories.Count() > 0)
     {
         AuraSftpClient.SFTPTransactionVoid(prj.Connection.Data, (RenciSftpClient client) =>
         {
             var dirs          = prj.Data.Map.Directories;
             var files         = prj.Data.Map.Files;
             SftpFilter filter = prj.Filter;
             foreach (var dir in dirs)
             {
                 client.Download(prj.Connection.Data, dir, filter, replace, silentDownload);
             }
             foreach (var file in files)
             {
                 prj.Connection.Data.Download(file, replace);
             }
         });
     }
     else
     {
         throw new Exception(MSG_ERR_PRJ_PULL_EMPTY_MAP);
     }
 }
Beispiel #3
0
        /// <summary>
        /// List the files inside a given directory
        /// </summary>
        /// <param name="client">The Sftp client</param>
        /// <param name="dirPath">The directory path</param>
        /// <param name="silentDownload">Download the files without listing everything</param>
        /// <returns>The file list collection</returns>
        public static IEnumerable <String> ListFiles(this RenciSftpClient client, string dirPath, SftpFilter filter, Boolean silentDownload = false)
        {
            List <String>        files = new List <String> ();
            IEnumerable <String> result;
            var entries = client.ListDirectory(dirPath);

            if (silentDownload)
            {
                Console.WriteLine("Downloading {0} entries...", entries.Count());
            }
            foreach (var entry in entries.Where(x => !x.IsDirectory))
            {
                if (filter.IsUnixFileValid(entry.FullName))
                {
                    files.Add(entry.FullName);
                }
            }
            result = files;
            foreach (var subDirPath in entries.Where(x => x.IsDirectory && filter.IsUnixDirValid(x)))
            {
                Console.WriteLine(subDirPath);
                result = result.Union(ListFiles(client, subDirPath.FullName, filter, silentDownload));
            }
            return(result);
        }