internal protected virtual void InvokeOnChangeDirectory(FtpChangeDirectoryArgs e) { if (this.OnChangeDirectory != null) this.OnChangeDirectory(this, e); }
public static void Cmd_CDUP(Object sender, CommandEventArgs e) { FtpSession lSession = (FtpSession)e.Session; if (lSession.State == FtpState.LoggedIn) { if (e.Parameters.Length != 0) { e.Connection.WriteLine("501 Syntax error in parameters or arguments."); } else { String lNewDir = lSession.Directory; if (lNewDir.Length > 2) { Int32 lNewLen = lNewDir.LastIndexOf('/', lNewDir.Length - 2); if (lNewLen <= 0) lNewLen = 1; lNewDir = lNewDir.Substring(0, lNewLen); if (lNewDir.Length == 0) lNewDir = "/"; } FtpChangeDirectoryArgs lEventArgs = new FtpChangeDirectoryArgs(e.Session, e.Connection, e.Server); lEventArgs.NewDirectory = lNewDir; try { ((FtpServer)e.Server).InvokeOnChangeDirectory(lEventArgs); } catch (FtpException ex) { e.Connection.WriteLine(ex.ToString()); return; } catch { e.Connection.WriteLine("500 Internal Error"); return; } if (lEventArgs.ChangeDirOk) { e.Connection.WriteLine("250 CDUP command successful."); lSession.Directory = lNewDir; } else { e.Connection.WriteLine("550 Permission Denied."); } } } else { e.Connection.WriteLine("503 Bad sequence of commands."); } }
protected override void InvokeOnChangeDirectory(FtpChangeDirectoryArgs ea) { string lPath = ea.NewDirectory; if (lPath.IndexOf('/') != 0) throw new Exception(String.Format("Not an absolute path: \"{0}\"", lPath)); VirtualFtpSession lSession = (VirtualFtpSession)ea.Session; IFtpFolder lFolder = fRootFolder.DigForSubFolder(lPath.Substring(1), lSession); if (lFolder != null) { ((VirtualFtpSession)ea.Session).CurrentFolder = lFolder; } ea.ChangeDirOk = (lFolder != null); base.InvokeOnChangeDirectory(ea); }
public static void Cmd_CWD(Object sender, CommandEventArgs e) { FtpSession lSession = (FtpSession)e.Session; if (lSession.State == FtpState.LoggedIn) { if (e.Parameters.Length == 0) { e.Connection.WriteLine("501 Syntax error in parameters or arguments."); } else { String lNewDir = e.AllParameters; if (lNewDir.StartsWith("/")) { lNewDir = ValidateDirectory(lNewDir); } else { String lTemp = lSession.Directory; if (!lTemp.EndsWith("/")) lTemp = lTemp + "/"; lNewDir = ValidateDirectory(lTemp + lNewDir); } FtpChangeDirectoryArgs lArgs = new FtpChangeDirectoryArgs(e.Session, e.Connection, e.Server); lArgs.NewDirectory = lNewDir; try { ((FtpServer)e.Server).InvokeOnChangeDirectory(lArgs); } catch (FtpException ex) { e.Connection.WriteLine(ex.ToString()); return; } catch { e.Connection.WriteLine("500 Internal Error"); return; } if (lArgs.ChangeDirOk) { e.Connection.WriteLine("250 CWD command successful, new folder is '{0}'.", lSession.Directory); lSession.Directory = lNewDir; } else { e.Connection.WriteLine("550 Permission Denied."); } } } else { e.Connection.WriteLine("503 Bad sequence of commands."); } }
private void OnChangeDirectory(object sender, FtpChangeDirectoryArgs e) { VirtualFtpServer server = (VirtualFtpServer)sender; VirtualFtpSession session = (VirtualFtpSession)e.Session; if (e.NewDirectory.Equals("/")) { session.CurrentFolder = server.RootFolder.GetSubFolder(session.Username, session); session.Directory = String.Format(@"/{0}/", session.Username); } }