/// <summary> /// Pops a directory change off of the stack and returns to the previous working directory. /// </summary> private void popDirectory() { string currPath = (string)pathStack.Pop(); string newPath = pathStack.Count > 0 ? (string)pathStack.Peek() : m_path; if (!currPath.Equals(newPath))//This optimization prevents needless CWD network I/O. { WinInet.FtpSetCurrentDirectory(m_hFtp, newPath); } }
/// <summary> /// Pushes a directory change onto the stack if a directory change is successful. /// This operation should be used to change directories because some FTP server /// behave strangely when performing operations outside of the target directory. /// This stack behavior makes it very easy for operations to transparently change /// directories and then return to the previous directory. /// </summary> /// <param name="path">the directory to change to</param> /// <returns>true if the directory change was successful</returns> private bool pushDirectory(string path) { Trace.Assert(path.StartsWith(PathDelimiter, StringComparison.OrdinalIgnoreCase), "pushDirectory called with an unexpected (relative) path: " + path); if (pathStack.Count > 0 && pathStack.Peek().Equals(path)) { //then we're already in the specified directory, so just push //the directory onto the stack and return true. //This optimization prevents needless CWD network I/O. pathStack.Push(path); return(true); } bool success = WinInet.FtpSetCurrentDirectory(m_hFtp, path); if (success) { pathStack.Push(path); } return(success); }