public void Test_Sftp_CreateDirectory_In_Forbidden_Directory() { if (Resources.USERNAME == "root") Assert.Fail("Must not run this test as root!"); using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("/sbin/test"); sftp.Disconnect(); } }
public void Test_Sftp_CreateDirectory_Already_Exists() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("test"); sftp.CreateDirectory("test"); sftp.Disconnect(); } }
public void Test_Sftp_CreateDirectory_Without_Connecting() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.CreateDirectory("test"); } }
public void Test_Sftp_CreateDirectory_In_Current_Location() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("test"); sftp.Disconnect(); } }
public void Test_Sftp_CreateDirectory_Invalid_Path() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("/abcdefg/abcefg"); sftp.Disconnect(); } }
public void Test_Sftp_DeleteDirectory() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("abcdef"); sftp.DeleteDirectory("abcdef"); sftp.Disconnect(); } }
public string CreateDirectory(string remoteDirectory) { if (_sftp.Exists(remoteDirectory)) { throw new DuplicateNameException("The directory " + remoteDirectory + " already exists on the server, please enter a unique name"); } _sftp.CreateDirectory(remoteDirectory); if (!remoteDirectory.EndsWith("/")) { remoteDirectory += "/"; } return(remoteDirectory); }
public void CreateFolder() { using (SftpClient con = CreateConnection(false)) { //Bugfix, some SSH servers do not like a trailing slash string p = m_path; if (p.EndsWith("/")) { p.Substring(0, p.Length - 1); } con.CreateDirectory(p); } }
private static void ensureDirectoryExists(SftpClient client, string destination) { var directory = "/"; foreach (var splitPart in destination.Split('/').Where(x => !string.IsNullOrWhiteSpace(x) && !x.Contains("."))) { directory = Path.Combine(directory, splitPart).Replace("\\", "/"); if (!client.Exists(directory)) { client.CreateDirectory(directory); } } }
public override string GetCommandText(ActConsoleCommand act) { string cmd = ""; switch (act.ConsoleCommand) { case ActConsoleCommand.eConsoleCommand.FreeCommand: return(GetParameterizedCommand(act)); case ActConsoleCommand.eConsoleCommand.ParametrizedCommand: return(GetParameterizedCommand(act)); case ActConsoleCommand.eConsoleCommand.Script: VerifyFTPConnected(); if (!UnixFTPClient.Exists(workdir + @"/Ginger")) { UnixFTPClient.CreateDirectory(workdir + @"/Ginger"); } string SHFilesPath = mScriptsFolder; string UnixScriptFilePath = workdir + @"/Ginger/" + act.ScriptName; using (var f = File.OpenRead(SHFilesPath + act.ScriptName)) { UnixFTPClient.UploadFile(f, UnixScriptFilePath, null); } UnixFTPClient.ChangePermissions(UnixScriptFilePath, 777); foreach (var p in act.InputValues) { if (!string.IsNullOrEmpty(p.Value)) { cmd += " " + p.ValueForDriver; } } if (UnixScriptFilePath.Trim().EndsWith(".sh", StringComparison.CurrentCultureIgnoreCase)) { return("dos2unix " + UnixScriptFilePath + ";sh " + UnixScriptFilePath + cmd); } else { return("dos2unix " + UnixScriptFilePath + "; " + UnixScriptFilePath + cmd); } default: Reporter.ToLog(eLogLevel.WARN, "Error - unknown command"); ErrorMessageFromDriver += "Error - unknown command"; return("Error - unknown command"); } }
internal static bool DirectoryDeleteCreate(SftpClient client, string remotePath) { try { client.DeleteDirectory(remotePath); client.CreateDirectory(remotePath); } catch { return(false); } return(true); }
public static ChannelSettings CreateIfNotExists(this ChannelSettings target) { var info = target.AsConnectionInfo(); using (SftpClient client = new SftpClient(info)) { client.Connect(); if (!client.Exists(target.Path)) { client.CreateDirectory(target.Path); } } return(target); }
//检查路径是否存在,如果不存在就新建路径 public void CheckDir(string targetDir) { try { if (!sftpClient.Exists(targetDir)) { sftpClient.CreateDirectory(targetDir); } } catch (Exception ex) { throw new Exception(string.Format("新建路径失败,原因:{0}", ex.Message)); } }
/// <summary> /// Создать папку на удаленом сервере /// </summary> /// <param name="path">Полный путь папки на сервере</param> /// <param name="NotReport">Не заносить ошибку в отчет</param> public bool CreateDirectory(string path, bool NotReport = false) { try { switch (typeSunc) { case TypeSunc.SFTP: { sftp.CreateDirectory(path); return(true); } case TypeSunc.FTP: { ftp.CreateDirectory(path); return(true); } case TypeSunc.WebDav: { var res = webDav.Mkcol(path).Result; if (res.StatusCode == 201) { return(true); } if (!NotReport) { report.Base("CreateDirectory", path, res); } return(createDirectory(path)); } case TypeSunc.OneDrive: { oneDrive.GetFolderOrCreate(path).Wait(); return(true); } } } catch (Exception ex) { if (!NotReport) { report.Base("CreateDirectory", path, ex.ToString()); } } return(false); }
public void CreateSessionDirectory(Guid sessionGuid) { if (sessionGuid.Equals(Guid.Empty)) { throw new ArgumentException(); } EnsureIsInitialized(); // create session directory string SessionDir = CombinePaths( path, StandardFsDriver.SessionsDir, sessionGuid.ToString()); sftp.CreateDirectory(SessionDir); }
private static void CreateDirectory(SftpClient sftp, AbstractPath directory) { if (directory.FullName == "") { return; } if (sftp.Exists(directory.SlashPath)) { return; } CreateDirectory(sftp, directory.Parent); sftp.CreateDirectory(directory.SlashPath); }
public static void CreateFullDirectory(this SftpClient client, string path) { var parts = path.Split('/'); var currentPath = "."; foreach (var part in parts) { var newPath = currentPath + "/" + part; if (!client.Exists(newPath)) { client.CreateDirectory(newPath); } currentPath = newPath; } }
internal static bool DirectoryExistsOrCreate(SftpClient client, string remotePath) { try { if (!client.Exists(remotePath)) { client.CreateDirectory(remotePath); } } catch (Renci.SshNet.Common.SftpPermissionDeniedException) { return(false); } return(true); }
public override async Task CreateDirectoryAsync(string path, CancellationToken cancellationToken = default) { if (await DirectoryExistsAsync(path, cancellationToken)) { throw new DirectoryExistsException(PrependRootPath(path), Prefix); } try { await Task.Run(() => client.CreateDirectory(PrependRootPath(path)), cancellationToken); } catch (Exception exception) { throw Exception(exception); } }
public void Test_Sftp_CreateDirectory_In_Forbidden_Directory() { if (Resources.USERNAME == "root") { Assert.Fail("Must not run this test as root!"); } using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("/sbin/test"); sftp.Disconnect(); } }
/// <inheritdoc /> public async Task CreateDirectoryAsync(string directoryName) { if (string.IsNullOrWhiteSpace(directoryName)) { throw new ArgumentNullException(paramName: nameof(directoryName), message: "Directory name must not be null."); } try { sftpClient.Connect(); await Task.Run(() => sftpClient.CreateDirectory(directoryName)); } finally { sftpClient.Disconnect(); } }
public static void sFtpCreateFolderByCurrentDate() { if (sFtpCheckConnection()) { Console.Clear(); using (sFtpClient = new SftpClient(connectionInfo)) { sFtpClient.Connect(); if (sFtpClient.IsConnected) { clsConsole.WriteLine("\r\n ======= sFtp check folder existed =======", ConsoleColor.Red); if (!sFtpCheckFolderExists(rmCaselawPath)) { clsConsole.WriteLine(string.Format(" ***** Folder on sFtp {0} has been created. ***** ", rmCaselawPath), ConsoleColor.Cyan); sFtpClient.CreateDirectory(rmCaselawPath); } if (!sFtpCheckFolderExists(rmNonVirgoPath)) { clsConsole.WriteLine(string.Format(" ***** Folder on sFtp {0} has been created. ***** ", rmNonVirgoPath), ConsoleColor.Cyan); sFtpClient.CreateDirectory(rmNonVirgoPath); } if (!sFtpCheckFolderExists(rmVirgoPath)) { clsConsole.WriteLine(string.Format(" ***** Folder on sFtp {0} has been created. ***** ", rmVirgoPath), ConsoleColor.Cyan); sFtpClient.CreateDirectory(rmVirgoPath); } if (!sFtpCheckFolderExists(rmCaseRelatedPath)) { clsConsole.WriteLine(string.Format(" ***** Folder on sFtp {0} has been created. ***** ", rmCaseRelatedPath), ConsoleColor.Cyan); sFtpClient.CreateDirectory(rmCaseRelatedPath); } if (!sFtpCheckFolderExists(rmStateNetPath)) { clsConsole.WriteLine(string.Format(" ***** Folder on sFtp {0} has been created. ***** ", rmStateNetPath), ConsoleColor.Cyan); sFtpClient.CreateDirectory(rmStateNetPath); } if (!sFtpCheckFolderExists(rmSecuritiesMosaicPath)) { clsConsole.WriteLine(string.Format(" ***** Folder on sFtp {0} has been created. ***** ", rmSecuritiesMosaicPath), ConsoleColor.Cyan); sFtpClient.CreateDirectory(rmSecuritiesMosaicPath); } sFtpClient.Disconnect(); } } } }
private string CalculateTargetFolder() { string targetFolder = UnixPathCalculated; if (UnixFTPClient.Exists(UnixPathCalculated) == false) { //if path given by user does not exist upload it to /Ginger/Upload targetFolder = Path.Combine(workdir, "Ginger/Uploaded").Replace("\\", "/"); if (UnixFTPClient.Exists(targetFolder) == false) { UnixFTPClient.CreateDirectory(targetFolder); } } return(targetFolder); }
public bool mkdir(string path) { try { if (!client.Exists(path)) { client.CreateDirectory(path); } return(true); } catch (System.Exception e) { Debug.LogError(e); return(false); } }
/// <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); } }
/// <summary> /// 保存到联贷平台SFTP /// </summary> public bool SaveToGFSftp(string remotePath, Stream fileStream, string fileName) { var isSuccess = false; try { using (var client = new SftpClient(gfFtpIp, int.Parse(gfFtpPort), gfFtpAccount, gfFtpPassword)) //创建连接对象 { client.Connect(); //连接 if (!client.Exists(remotePath)) { var paths = remotePath.Split('/'); if (paths.Length > 1) { var path = ""; foreach (var p in paths) { path += "/" + p; if (!client.Exists(path)) { client.CreateDirectory(path); } } } } client.ChangeDirectory(remotePath); //切换目录 client.UploadFile(fileStream, fileName); //上传文件 var stpFile = client.Get(fileName); if (stpFile.IsRegularFile) { isSuccess = true; } client.Disconnect(); } } catch (Exception ex) { AppUtility.Engine.LogWriter.Write($"联贷平台SFTP上传{remotePath}/{fileName}文件错误{ex.ToString()}"); } return(isSuccess); }
/* * A little redundant that this function requires a deviceip and user and password when you're handing it an already connected sftpclient * but for the sake of making this a little more reusable I've made it this way. This is due to the requirement of using an ssh client * to remove destination folders if required. Solution is to make this ssh directory removal a recursive sftpClient function. * TODO: Write recursive delete for SftpClient. */ /// <summary> /// <b>Expects SftpClient object to already be in a connected state.</b><br/> /// Recursively copies all files and folders under the base directory given including creating the base directory itself at the target location.<br/> /// Target location string is required to be in unix format. eg. /home/pi/PFC/scp-dg-doorpanel /// </summary> /// <param name="sftpClient">SftpClient object is required to be connected.</param> /// <param name="sourceDirName">Path to directory of source files. This directory itself is copied and all contents.</param> /// <param name="destDirName">Path to folder you wish your selected source folder to be copied to. (unix file path format required. eg. /home/pi/cooldevstuff)</param> /// <param name="copySubDirs">Set to true for a recursive file copy. Otherwise only contents of root folder are copied.</param> /// <param name="purgeDestination">Set this to true if you wish for any files / folders at the destination to be removed replaced.</param> void LinuxRemoteCopy(SftpClient sftpClient, string deviceIP, string userName, string password, string sourceDirName, string destDirName, bool copySubDirs, bool purgeDestination) { // Get the subdirectories for the specified directory. DirectoryInfo dir = new DirectoryInfo(sourceDirName); DirectoryInfo[] dirs = dir.GetDirectories(); if (purgeDestination) { /* * An ugly hack to forceably delete the directory. SftpClient does not natively support a recursive delete * function so rather than writing up a whole recursive delete function myself, just connect with an ssh client and * remove the directory with regular shell commands. ¯\_(ツ)_/¯ */ SshClient ssh = new SshClient(deviceIP, userName, password); ssh.Connect(); ssh.RunCommand("sudo rm -rf " + destDirName); ssh.Disconnect(); } sftpClient.CreateDirectory(destDirName); // Get the files in the directory and copy them to the new location. FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { string temppath = System.IO.Path.Combine(destDirName, file.Name); temppath = temppath.Replace("\\", "/"); //file.CopyTo(temppath, false); using (var fileStream = File.OpenRead(file.FullName)) { sftpClient.UploadFile(fileStream, temppath, true); } } // If copying subdirectories, copy them and their contents to new location. if (copySubDirs) { foreach (DirectoryInfo subdir in dirs) { string temppath = System.IO.Path.Combine(destDirName, subdir.Name); temppath = temppath.Replace("\\", "/"); //Don't delete stuff on recursive calls, only delete root folder on initial call LinuxRemoteCopy(sftpClient, deviceIP, userName, password, subdir.FullName, temppath, copySubDirs, false); } } }
private void listv1_Click(object sender, MouseEventArgs e) { if (e.Button.Equals(MouseButtons.Right)) { //오른쪽 메뉴를 만듭니다 ContextMenu m = new ContextMenu(); //메뉴에 들어갈 아이템을 만듭니다 MenuItem m1 = new MenuItem(); MenuItem m2 = new MenuItem(); m1.Text = "업로드하기"; m2.Text = "다운로드하기"; //업로드하기 클릭시 이벤트 m1.Click += (senders, es) => { //ftp연결 sftp = new SftpClient(host, username, password); sftp.Connect(); Console.WriteLine("업로드클릭"); Console.WriteLine(pub_link); FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowDialog(); string select_path = dialog.SelectedPath; string select_name; DirectoryInfo dirinfo = new DirectoryInfo(select_path); select_name = dirinfo.Name; sftp.CreateDirectory("./folder1/" + select_name); UploadDirectory(sftp, select_path, "./folder1/" + select_name); }; m.MenuItems.Add(m1); m.MenuItems.Add(m2); m.Show(listView1, new Point(e.X, e.Y)); } }
private static bool Send(string fileName, string outgoingFilePath) { var connectionInfo = new ConnectionInfo(host, port, username, new PasswordAuthenticationMethod(username, password)); // Upload File try { using (var sftp = new SftpClient(connectionInfo)) { sftp.Connect(); if (!sftp.Exists(sftp_server_folder)) { sftp.CreateDirectory(sftp_server_folder); logWriter.Info("Remote folder created =>" + sftp_server_folder); } sftp.ChangeDirectory(sftp_server_folder); logWriter.Info("Remote folder is changed to =>" + sftp_server_folder); using (var uplfileStream = System.IO.File.OpenRead(outgoingFilePath)) { sftp.UploadFile(uplfileStream, fileName, true); logWriter.Info("File is uploaded =>" + fileName); } sftp.Disconnect(); logWriter.Info("sftp is disconnected=>"); } } catch (Renci.SshNet.Common.SshConnectionException ex) { logWriter.Error("Cannot connect to the server. =>" + ex.Message); return(false); } catch (System.Net.Sockets.SocketException ex) { logWriter.Error("Unable to establish the socket. =>" + ex.Message); return(false); } catch (Renci.SshNet.Common.SshAuthenticationException ex) { logWriter.Error("Authentication of SSH session failed. =>" + ex.Message); return(false); } return(true); }
public void CreateDirectory(string server, int port, string directory) { directory = AdjustPath(server, directory); string d = "/" + server; foreach (string i in directory.Split('/')) { d = d + "/" + i; if (!DirectoryExists(server, port, d)) { SftpClient client = null; try { client = OpenSftpClient(server, port); try { string dir = AdjustPath(server, d); client.CreateDirectory(dir); } finally { RecycleClient(client); client = null; } } catch { try { client.Disconnect(); } catch { } try { client.Dispose(); } catch { } throw; } } } }
/// <summary> /// 递归创建文件夹 /// </summary> /// <param name="serverDestinationPath"></param> private void CreateServerDirectoryIfItDoesntExist(string serverDestinationPath) { if (serverDestinationPath[0] == '/') { serverDestinationPath = serverDestinationPath.Substring(1); } string[] directories = serverDestinationPath.Split('/'); for (int i = 0; i < directories.Length; i++) { string dirName = string.Join("/", directories, 0, i + 1); if (!_sftpClient.Exists(dirName)) { _sftpClient.CreateDirectory(dirName); } } }
private void button_CloudServer_AddCluster_Click(object sender, RoutedEventArgs e) { SftpClient client = ServersManager.GetExistSftp(m_ServerConnect, UI.Location, UI.Username, UI.Password); if (client == null) { return; } string userPath = (UI.Username == "root") ? "/root" : $"/home/{UI.Username}"; try { client.CreateDirectory($"{userPath}/.klei/{textBox_CloudServer_ClusterSaveList_AddPath.Text}"); } catch (SshException) { } catch (Exception) { throw; }; UI.SaveFolders_Cloud.Add(textBox_CloudServer_ClusterSaveList_AddPath.Text); }
public void CreateDirectory(string path) { if (Connect()) { try { client.CreateDirectory(path); } catch (SftpPathNotFoundException) { CreateMultiDirectory(path); } catch (SftpPermissionDeniedException) { } } }
private void ChangeServerPath(SftpClient sftp, string serverPath) { var serverPathParts = GetServerPath(serverPath).Split('/'); foreach (var serverPathPart in serverPathParts) { try { sftp.ChangeDirectory(serverPathPart); } catch { sftp.CreateDirectory(serverPathPart); sftp.ChangeDirectory(serverPathPart); } } }
private static async Task UploadFiles(string timestamp, string outputPath, string rsaPrivate, string sftpHost, string sftpUsername) { using var client = new SftpClient(sftpHost, sftpUsername, new PrivateKeyFile(File.OpenRead(rsaPrivate))) { BufferSize = 4096, OperationTimeout = TimeSpan.FromHours(1), }; client.Connect(); client.CreateDirectory(timestamp); foreach (var file in Directory.GetFiles(outputPath)) { using var zipUpload = File.OpenRead(file); await Task.Factory.FromAsync((callback, stateObject) => client.BeginUploadFile(zipUpload, $"{timestamp}\\{Path.GetFileName(file)}", callback, stateObject), result => client.EndUploadFile(result), null); } client.Disconnect(); }
public void CreateDirectory(string Path) { try { client.CreateDirectory(Path); DebugHelper.WriteLine("Created Directory: " + Path); } catch (SftpPathNotFoundException) { DebugHelper.WriteLine("Failed to create directory " + Path); DebugHelper.WriteLine("Attempting to fix..."); CreateMultipleDirectorys(FTPHelpers.GetPaths(Path)); } catch (SftpPermissionDeniedException) { } }
public void Test_Sftp_CreateDirectory_Null() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.CreateDirectory(null); } }
public void CreateDirectoryTest() { ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value string path = string.Empty; // TODO: Initialize to an appropriate value target.CreateDirectory(path); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
private static void CreatSSHDir(SftpClient ssh, string file) { var newDir = Tools.Misc.GetUnixDirecoryOfFile(file); if (ssh.Exists(newDir)) return; string[] dirs = new string[newDir.ToCharArray().Count(x => x == '/')]; dirs[0] = newDir; for (int i = 1; i < dirs.Count(); i++) { dirs[i] = Tools.Misc.GetUnixDirecoryOfFile(dirs[i - 1]); } for (int i = dirs.Count()-1; i >= 0; i--) { if (ssh.Exists(dirs[i])) continue; ssh.CreateDirectory(dirs[i]); } }
public void Test_Sftp_ListDirectory_HugeDirectory() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); // Create 10000 directory items for (int i = 0; i < 10000; i++) { sftp.CreateDirectory(string.Format("test_{0}", i)); Debug.WriteLine("Created " + i); } var files = sftp.ListDirectory("."); // Ensure that directory has at least 10000 items Assert.IsTrue(files.Count() > 10000); sftp.Disconnect(); } }
public void Test_Sftp_Change_Directory() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester"); sftp.CreateDirectory("test1"); sftp.ChangeDirectory("test1"); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1"); sftp.CreateDirectory("test1_1"); sftp.CreateDirectory("test1_2"); sftp.CreateDirectory("test1_3"); var files = sftp.ListDirectory("."); Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory))); sftp.ChangeDirectory("test1_1"); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1"); sftp.ChangeDirectory("../test1_2"); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_2"); sftp.ChangeDirectory(".."); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1"); sftp.ChangeDirectory(".."); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester"); files = sftp.ListDirectory("test1/test1_1"); Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory))); sftp.ChangeDirectory("test1/test1_1"); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1"); sftp.ChangeDirectory("/home/tester/test1/test1_1"); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_1"); sftp.ChangeDirectory("/home/tester/test1/test1_1/../test1_2"); Assert.AreEqual(sftp.WorkingDirectory, "/home/tester/test1/test1_2"); sftp.ChangeDirectory("../../"); sftp.DeleteDirectory("test1/test1_1"); sftp.DeleteDirectory("test1/test1_2"); sftp.DeleteDirectory("test1/test1_3"); sftp.DeleteDirectory("test1"); sftp.Disconnect(); } }