public FtpResponse ChangeCurrentDirectoryToHome() { FtpResponse resp = null; string comPath = null; int comDepth = 0; // compare the current path to the home path. Pather.GetCommonPath( out comPath, out comDepth, CompleteHomePath.ToString(), CurrentPath.ToString()); // start of current directory must match the CompleteHomePath int homeDepth = CompleteHomePath.Depth; if (comDepth != homeDepth) { throw new FtpException( "AssureHomeDirectory failed. " + "Current directory does not start with HomePath. "); } while (true) { int curDepth = mCurrentPath.Depth; if (curDepth == homeDepth) { break; } resp = ChangeDirectory(".."); } return(resp); }
/// <summary> /// make sure the current working directory is the ScopePath from /// the CompleteHomePath. /// This method assumes that the CurrentPath is accurate with respect /// to the working directory of the FTP client. /// </summary> /// <param name="InPath"></param> /// <returns></returns> public FtpResponse AssureCurrentDirectory(ScopePath InPath) { FtpResponse resp = null; string comPath = null; int comDepth = 0; // build the desired full path. FullPath rqsFull = CompleteHomePath + InPath; int rqsDepth = rqsFull.Depth; // step back the CurrentPath to a subset of requested path. while (true) { Pather.GetCommonPath( out comPath, out comDepth, rqsFull.ToString(), CurrentPath.ToString()); if (comDepth < CurrentPath.Depth) { resp = ChangeDirectory(".."); } else { break; } } string filePath = Pather.GetFilePath(rqsFull.ToString(), CurrentPath.ToString()); if (filePath.Length > 0) { if (mCurrentPath.IsEmpty == true) { filePath = Pather.AssureRootSlash(filePath, '\\'); } ChangeDirectory(filePath); } return(resp); }