当前位置: 首页>>代码示例>>C#>>正文


C# SftpClient.SynchronizeDirectories方法代码示例

本文整理汇总了C#中Renci.SshNet.SftpClient.SynchronizeDirectories方法的典型用法代码示例。如果您正苦于以下问题:C# SftpClient.SynchronizeDirectories方法的具体用法?C# SftpClient.SynchronizeDirectories怎么用?C# SftpClient.SynchronizeDirectories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SftpClient的用法示例。


在下文中一共展示了SftpClient.SynchronizeDirectories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SyncTo

 /// <summary>
 /// Sync output of current compilation to <paramref name="dir"/>
 /// </summary>
 /// <param name="dir"></param>
 /// <returns></returns>
 private bool SyncTo(string dir)
 {
     // Copy files over
     using (var sftp = new SftpClient(Machine, Port, Username, Password))
     {
         sftp.Connect();
         if (!sftp.IsConnected)
         {
             return false;
         }
         // Perform recursive copy of all the folders under `dir`. This is required
         // as the sftp client only synchronize directories at their level only, no
         // subdirectory.
         var dirs = new Queue<DirectoryInfo>();
         dirs.Enqueue(new DirectoryInfo(dir));
         var parentPath = new UDirectory(dir);
         while (dirs.Count != 0)
         {
             var currentDir = dirs.Dequeue();
             var currentPath = new UDirectory(currentDir.FullName);
             foreach (var subdir in currentDir.EnumerateDirectories())
             {
                 dirs.Enqueue(subdir);
             }
             // Get the destination path by adding to `Location` the relative path of `dir` to `currentDir`.
             var destination = UPath.Combine(new UDirectory(Location.ItemSpec), currentPath.MakeRelative(parentPath));
             Log.LogMessage("Synchronizing " + currentPath + " with " + destination.FullPath);
             // Try to create a remote directory. If it throws an exception, we will assume
             // for now that the directory already exists. See https://github.com/sshnet/SSH.NET/issues/25
             try
             {
                 sftp.CreateDirectory(destination.FullPath);
                 Log.LogMessage("Creating remote directory " + destination.FullPath);
             }
             catch (SshException)
             {
                 // Do nothing, as this is when the directory already exists
             }
             // Synchronize files.
             foreach (var file in sftp.SynchronizeDirectories(currentPath.FullPath, destination.FullPath, "*"))
             {
                 Log.LogMessage("Updating " + file.Name);
             }
         }
         return true;
     }
 }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:52,代码来源:PackageDeployTask.cs


注:本文中的Renci.SshNet.SftpClient.SynchronizeDirectories方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。