Пример #1
0
        /// <summary>
        /// Maps a directory to the project file
        /// </summary>
        /// <param name="prj">The project file</param>
        /// <param name="path">The mapped directory data</param>
        private void MapDirectory(Project prj, MappedPath path)
        {
            String error_msg = null;
            var    result    = AuraSftpClient.SFTPTransactionGen <MappedPath> (prj.Connection.Data,
                                                                               (RenCiSftpClient client) => {
                String rPth = path.GetFullRemotePath();
                if (client.Exists(rPth))
                {
                    var entry          = client.Get(rPth);
                    path.RemoteVersion = entry.LastAccessTime;
                    Boolean mapExist   = prj.Data.Map.Directories.FirstOrDefault(x => x.GetFullRemotePath() == entry.FullName) != null;
                    if (entry.IsDirectory && !mapExist)
                    {
                        if (!Directory.Exists(path.GetFullProjectCopy()))
                        {
                            Directory.CreateDirectory(path.GetFullProjectCopy());
                        }
                        if (!Directory.Exists(path.GetFullServerCopy()))
                        {
                            Directory.CreateDirectory(path.GetFullServerCopy());
                        }
                    }
                    else if (!entry.IsDirectory)
                    {
                        error_msg = String.Format(MSG_ERR_MAP_REM_PTH_NOT_DIR, rPth, HelpCommand, "dir");
                    }
                    else if (mapExist)
                    {
                        error_msg = String.Format(MSG_ERR_MAP_AlREADY_MAPPED, rPth);
                    }
                }
                else
                {
                    error_msg = String.Format(MSG_ERR_MAP_REM_PTH, rPth);
                }
                return(path);
            });

            if (result != null && error_msg == null)
            {
                prj.Data.Map.Directories = prj.Data.Map.Directories.Union(new MappedPath[] { result }).ToArray();
                prj.SaveProject(this.ConfigFile);
                Console.WriteLine(String.Format(MSG_INF_MAP_CREATED, result.GetFullRemotePath(), result.GetFullProjectCopy()));
            }
            else if (error_msg != null)
            {
                Console.WriteLine(error_msg);
            }
        }
Пример #2
0
        /// <summary>
        /// Downloads a file
        /// </summary>
        /// <param name="credentials">The ssh site credentials</param>
        /// <param name="fileMap">The mapping file to download</param>
        /// <param name="replace">True if the downloaded file will be replaced</param>
        public static void Download(this SiteCredentials credentials, MappedPath fileMap, Boolean replace)
        {
            FileInfo sC, lC;

            AuraSftpClient.SSHTransactionVoid(credentials, (AuraSftpClient c) => {
                sC = new FileInfo(fileMap.GetFullServerCopy());
                lC = new FileInfo(fileMap.GetFullProjectCopy());
                DownloadFile(c, fileMap.GetFullRemotePath(), sC, lC, replace);
            });
        }
Пример #3
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);
                }
            }));
        }