/// <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;
     }
 }
        public void TestMakeRelative()
        {
            UPath assetPath2 = null;
            UPath newAssetPath2 = null;
            var dir1 = new UDirectory("/a/b/c");

            var assetDir2 = new UDirectory("/a/b/c");
            newAssetPath2 = dir1.MakeRelative(assetDir2);
            Assert.AreEqual(".", newAssetPath2.FullPath);

            var assetDir3 = new UDirectory("/a/b");
            newAssetPath2 = dir1.MakeRelative(assetDir3);
            Assert.AreEqual("c", newAssetPath2.FullPath);

            var assetDir4 = new UDirectory("/a/b/c/d");
            newAssetPath2 = dir1.MakeRelative(assetDir4);
            Assert.AreEqual("..", newAssetPath2.FullPath);

            // Test direct relative
            assetPath2 = new UFile("/a/b/c/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("test.txt", newAssetPath2.FullPath);

            // Test direct relative + subdir
            assetPath2 = new UFile("/a/b/c/test/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("test/test.txt", newAssetPath2.FullPath);

            // Test relative 1
            assetPath2 = new UFile("/a/b/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../test.txt", newAssetPath2.FullPath);

            // Test relative 2
            assetPath2 = new UFile("/a/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../test.txt", newAssetPath2.FullPath);

            // Test relative 3
            assetPath2 = new UFile("/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);

            // Test already relative
            assetPath2 = new UFile("../test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../test.txt", newAssetPath2.FullPath);

            // Test only root path in common
            assetPath2 = new UFile("/e/f/g/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../e/f/g/test.txt", newAssetPath2.FullPath);

            // Test only root path in common with single file
            assetPath2 = new UFile("/test.txt");
            newAssetPath2 = assetPath2.MakeRelative(dir1);
            Assert.AreEqual("../../../test.txt", newAssetPath2.FullPath);
        }