本文整理汇总了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;
}
}