public override void DeleteFile(String fileName, VirtualFtpSession session) { if (!HasFile(fileName)) { throw new FtpException(String.Format("A file named \"{0}\" does not exists.", fileName)); } if (!AllowDeleteItems(session)) { throw new FtpException(550, String.Format("Cannot delete fike \"{0}\", permission to delete from this folder denied.", fileName)); } IFtpFile lFile = GetFile(fileName, session); if (!lFile.AllowDelete(session)) { throw new FtpException(550, String.Format("Cannot delete file \"{0}\", permission to delete file denied.", fileName)); } lock (this) { lFile.Invalidate(); FileList.Remove(fileName.ToLower()); } }
public override void DeleteFolder(String folder, Boolean recursive, VirtualFtpSession session) { if (!HasSubfolder(folder)) { throw new FtpException(String.Format("A folder named \"{0}\" does not exists.", folder)); } if (!AllowDeleteItems(session)) { throw new FtpException(550, String.Format("Cannot delete folder \"{0}\", permission to delete from this folder denied.", folder)); } IFtpFolder lFolder = GetSubFolder(folder, session); if (!lFolder.AllowDeleteThis(session)) { throw new FtpException(550, String.Format("Cannot delete folder \"{0}\", permission to delete folder denied.", folder)); } lock (this) { lFolder.Invalidate(); SubFolderList.Remove(folder.ToLower()); } }
public IFtpFolder DigForSubFolder(String fullPath, VirtualFtpSession session) { if (fullPath.Length == 0) { return(this); } Int32 lSeparatorIndex = fullPath.IndexOf('/'); if (lSeparatorIndex < 0) { return(this.GetSubFolder(fullPath, session)); } String lSubFolder = fullPath.Substring(0, lSeparatorIndex); IFtpFolder lFolder = GetSubFolder(lSubFolder, session); if (lFolder == null) { return(null); } fullPath = fullPath.Substring(lSeparatorIndex + 1); return(lFolder.DigForSubFolder(fullPath, session)); }
lListingItem.GroupWrite = GroupWrite; lListingItem.GroupExec = false; lListingItem.OtherRead = WorldRead; lListingItem.OtherWrite = WorldWrite; lListingItem.OtherExec = false; }
{ if (aFullPath.Length == 0) return this; int p = aFullPath.IndexOf('/'); if (p >= 0) { string lSubFolder = aFullPath.Substring(0,p); IFtpFolder lFolder = GetSubFolder(lSubFolder, aSession); if (lFolder != null) { aFullPath = aFullPath.Substring(p+1); return lFolder.DigForSubFolder(aFullPath, aSession); } else { return null; } } else { return GetSubFolder(aFullPath, aSession); } } public void FindBaseFolderForFilename(string aPath, out IFtpFolder aFolder, out string aFilename, VirtualFtpSession aSession) {
protected override void InvokeOnGetListing(FtpGetListingArgs e) { VirtualFtpSession lSession = (VirtualFtpSession)e.Session; lSession.CurrentFolder.ListFolderItems(e.Listing); base.InvokeOnGetListing(e); }
} } public class UserManager: Hashtable, IFtpUserManager { public UserManager(): base () { }
public sealed override IFtpFolder CreateFolder(String folder, VirtualFtpSession session) { if (!AllowMkDir(session)) { throw new FtpException(550, String.Format("Cannot create folder \"{0}\", permission to mkdir in this folder denied.", folder)); } return(DoCreateFolder(folder, session)); }
public sealed override IFtpFile CreateFile(String fileName, VirtualFtpSession session) { if (!AllowPut(session)) { throw new FtpException(550, String.Format("Cannot create file \"{0}\", permission to upload to this folder denied.", fileName)); } return(DoCreateFile(fileName, session)); }
protected override void InvokeOnCanStoreFile(FtpTransferEventArgs e) { VirtualFtpSession lSession = (VirtualFtpSession)e.Session; IFtpFolder lFolder; String lFilename; lSession.CurrentFolder.FindBaseFolderForFilename(e.FileName, out lFolder, out lFilename, lSession); e.Ok = lFolder.AllowPut(lSession); }
public override bool HasSubfolder(string aFolderName) { return SubFolderList.ContainsKey(aFolderName.ToLower()); } public override bool HasFile(string aFileame) { return FileList.ContainsKey(aFileame.ToLower()); } #endregion #region Get*
#region Get* public override IFtpFolder GetSubFolder(string aFolderName, VirtualFtpSession aSession) { if (!AllowBrowse(aSession)) throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to access items in this folder denied.",aFolderName)); IFtpFolder lFolder = SubFolderList[aFolderName.ToLower()] as IFtpFolder; if (lFolder != null && !lFolder.AllowBrowse(aSession)) throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to browse folder denied.",aFolderName)); return lFolder; }
protected override void InvokeOnUserLogin(FtpUserLoginEventArgs e) { if (UserManager == null) { return; } VirtualFtpSession lSession = (VirtualFtpSession)e.Session; e.LoginOk = UserManager.CheckLogin(e.UserName, e.Password, lSession); base.InvokeOnUserLogin(e); }
protected override void InvokeOnRename(FtpRenameEventArgs e) { VirtualFtpSession lSession = (VirtualFtpSession)e.Session; IFtpFolder lFolder; String lFilename; lSession.CurrentFolder.FindBaseFolderForFilename(e.FileName, out lFolder, out lFilename, lSession); lFolder.RenameFileOrFolder(lFilename, e.NewFileName, lSession); e.Ok = true; }
public virtual Boolean CheckLogin(String username, String password, VirtualFtpSession session) { User lUser = (User)this[username.ToLower()]; if (lUser == null) return false; if (lUser.Password != password) return false; return true; }
protected override void InvokeOnMakeDirectory(FtpFileEventArgs e) { VirtualFtpSession lSession = (VirtualFtpSession)e.Session; IFtpFolder lFolder; String lFilename; lSession.CurrentFolder.FindBaseFolderForFilename(e.FileName, out lFolder, out lFilename, lSession); lFolder.CreateFolder(lFilename, lSession); e.Ok = true; }
protected override void InvokeOnCanRetrieveFile(FtpTransferEventArgs e) { VirtualFtpSession lSession = (VirtualFtpSession)e.Session; IFtpFolder lFolder; String lFilename; lSession.CurrentFolder.FindBaseFolderForFilename(e.FileName, out lFolder, out lFilename, lSession); IFtpFile lFile = lFolder.GetFile(lFilename, lSession); e.Ok = (lFile != null && lFile.AllowRead(lSession)); }
public override IFtpFolder GetSubFolder(String folder, VirtualFtpSession session) { if (!AllowBrowse(session)) { throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to access items in this folder denied.", folder)); } if (!HasSubfolder(folder)) { throw new FtpException(550, String.Format("A folder named \"{0}\" does not exist.", folder)); } return(new DiscFolder(this, folder, Path.Combine(LocalPath, folder))); }
public override IFtpFolder GetSubFolder(String folder, VirtualFtpSession session) { //if (!AllowBrowse(session)) // throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to access items in this folder denied.", folder)); IFtpFolder lFolder = SubFolderList[folder.ToLower()] as IFtpFolder; if (lFolder != null && !lFolder.AllowBrowse(session)) { throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to browse folder denied.", folder)); } return(lFolder); }
public override void DeleteFolder(String folder, Boolean recursive, VirtualFtpSession session) { if (!AllowDeleteItems(session)) { throw new FtpException(550, String.Format("Cannot delete folder \"{0}\", permission to delete from this folder denied.", folder)); } if (!HasSubfolder(folder)) { throw new FtpException(550, String.Format("A folder named \"{0}\" does not exist.", folder)); } Directory.Delete(Path.Combine(LocalPath, folder), recursive); }
protected override void InvokeOnRetrieveFile(FtpTransferEventArgs e) { VirtualFtpSession lSession = (VirtualFtpSession)e.Session; IFtpFolder lFolder; String lFilename; lSession.CurrentFolder.FindBaseFolderForFilename(e.FileName, out lFolder, out lFilename, lSession); IFtpFile lFile = lFolder.GetFile(lFilename, lSession); lFile.GetFile(e.DataChannel); e.Ok = true; }
public override IFtpFile GetFile(String filename, VirtualFtpSession session) { if (!AllowGet(session)) { throw new FtpException(550, String.Format("Cannot retrieve file \"{0}\", permission to get files from this folder denied.", filename)); } if (!HasFile(filename)) { throw new FtpException(550, String.Format("A file named \"{0}\" does not exist.", filename)); } return(new DiscFile(this, filename, Path.Combine(LocalPath, filename))); }
public override IFtpFile CreateFile(String filename, VirtualFtpSession session) { if (!AllowPut(session)) { throw new FtpException(550, String.Format("Cannot upload file \"{0}\", permission to upload files to this folder denied.", filename)); } if (HasFile(filename)) { throw new FtpException(550, String.Format("A file named \"{0}\" already exist.", filename)); } return(new DiscFile(this, filename, Path.Combine(LocalPath, filename))); }
public override void DeleteFile(String filename, VirtualFtpSession session) { if (!AllowDeleteItems(session)) { throw new FtpException(550, String.Format("Cannot delete file \"{0}\", permission to delete from this folder denied.", filename)); } if (!HasFile(filename)) { throw new FtpException(550, String.Format("A file named \"{0}\" does not exist.", filename)); } File.Delete(Path.Combine(LocalPath, filename)); }
public override IFtpFolder CreateFolder(String folder, VirtualFtpSession session) { if (!AllowMkDir(session)) { throw new FtpException(550, String.Format("Cannot create folder \"{0}\", permission to mkdir in this folder denied.", folder)); } if (HasSubfolder(folder)) { throw new FtpException(550, String.Format("A folder named \"{0}\" already exist.", folder)); } Directory.CreateDirectory(Path.Combine(LocalPath, folder)); return(new DiscFolder(this, folder, Path.Combine(LocalPath, folder))); }
public virtual Boolean AllowRead(VirtualFtpSession session) { if (Invalid) return false; if (session.IsFileAdmin) return true; if (session.Username == OwningUser && UserRead) return true; if (WorldRead) return true; return false; }
public virtual Boolean CheckLogin(String username, String password, VirtualFtpSession session) { User lUser = (User)this[username.ToLower()]; if (lUser == null) { return(false); } if (lUser.Password != password) { return(false); } return(true); }
public override IFtpFile GetFile(string aFilename, VirtualFtpSession aSession) { if (!HasFile(aFilename)) throw new FtpException(String.Format("A file named \"{0}\" does not exists.",aFilename)); if (!AllowBrowse(aSession)) throw new FtpException(550,String.Format("Cannot access file \"{0}\", permission to access files in this folder denied.",aFilename)); IFtpFile lFile = FileList[aFilename.ToLower()] as IFtpFile; if (!lFile.AllowRead(aSession)) throw new FtpException(550, String.Format("Cannot access file \"{0}\", permission to access file denied.",aFilename)); return lFile; } #endregion #region Create* public override sealed IFtpFolder CreateFolder(string aFolderName, VirtualFtpSession aSession) { if (!AllowMkDir(aSession)) throw new FtpException(550, String.Format("Cannot create folder \"{0}\", permission to mkdir in this folder denied.",aFolderName)); return DoCreateFolder(aFolderName, aSession);
protected override IFtpFile DoCreateFile(string aFilename, VirtualFtpSession aSession) { if (HasFile(aFilename)) { throw new FtpException(String.Format("Cannot create file \"{0}\", a file with this name already exists.", aFilename)); } if (!AllowMkDir(aSession)) { throw new FtpException(550, String.Format("Cannot create file \"{0}\", permission denied.", aFilename)); } SecureFile lFile = new SecureFile(this, aFilename, fStorage); lFile.OwningUser = aSession.Username; Add(lFile); return(lFile); }
protected override void InvokeOnChangeDirectory(FtpChangeDirectoryArgs e) { String lPath = e.NewDirectory; if (lPath.IndexOf('/') != 0) { throw new Exception(String.Format("Not an absolute path: \"{0}\"", lPath)); } VirtualFtpSession lSession = (VirtualFtpSession)e.Session; IFtpFolder lFolder = RootFolder.DigForSubFolder(lPath.Substring(1), lSession); if (lFolder != null) { ((VirtualFtpSession)e.Session).CurrentFolder = lFolder; } e.ChangeDirOk = (lFolder != null); base.InvokeOnChangeDirectory(e); }
protected override IFtpFolder DoCreateFolder(string aFolderName, VirtualFtpSession aSession) { lock (this) { if (HasSubfolder(aFolderName)) { throw new FtpException(String.Format("Cannot create folder named \"{0}\", a folder with this name already exists.", aFolderName)); } if (!AllowMkDir(aSession)) { throw new FtpException(550, String.Format("Cannot create folder named \"{0}\", permission denied.", aFolderName)); } IFtpFolder lFolder = new SecureFolder(this, aFolderName, fStorage); lFolder.OwningUser = aSession.Username; Add(lFolder); return(lFolder); } }
get { return fSubFolderList; } } #region IFtpFolder implementation public abstract IEnumerable SubFolders { get ; } public abstract IEnumerable Files { get ; } public abstract bool HasSubfolder(string aFolderName); public abstract IFtpFolder GetSubFolder(string aFolderName, VirtualFtpSession aSession); public abstract IFtpFolder CreateFolder(string aFolderName, VirtualFtpSession aSession); public abstract void DeleteFolder(string aFolderName, bool aRecursive, VirtualFtpSession aSession); public abstract bool HasFile(string aFileame); public abstract IFtpFile GetFile(string aFilename, VirtualFtpSession aSession); public abstract IFtpFile CreateFile(string aFilename, VirtualFtpSession aSession); public abstract void DeleteFile(string aFilename, VirtualFtpSession aSession); public abstract void RenameFileOrFolder(string aOldFilename, string aNewFilename, VirtualFtpSession aSession); public abstract void RemoveItem(IFtpItem aItem); public IFtpFolder DigForSubFolder(string aFullPath, VirtualFtpSession aSession) {
public override IFtpFile GetFile(String fileName, VirtualFtpSession session) { if (!HasFile(fileName)) { throw new FtpException(String.Format("A file named \"{0}\" does not exists.", fileName)); } if (!AllowBrowse(session)) { throw new FtpException(550, String.Format("Cannot access file \"{0}\", permission to access files in this folder denied.", fileName)); } IFtpFile lFile = FileList[fileName.ToLower()] as IFtpFile; if ((lFile == null) || !lFile.AllowRead(session)) { throw new FtpException(550, String.Format("Cannot access file \"{0}\", permission to access file denied.", fileName)); } return(lFile); }
public virtual Boolean AllowWrite(VirtualFtpSession session) { if (Invalid) { return(false); } if (session.IsFileAdmin) { return(true); } if (session.Username == OwningUser && UserWrite) { return(true); } if (WorldWrite) { return(true); } return(false); }
public virtual Boolean AllowRead(VirtualFtpSession session) { if (Invalid) { return(false); } if (session.IsFileAdmin) { return(true); } if (session.Username.ToLower().Equals(OwningUser.ToLower()) && UserRead) { return(true); } if (WorldRead) { return(true); } return(false); }
int p = aPath.IndexOf('/');
while (p >= 0) {
aPath = aPath.Substring(1); /* remove / */ }
else {
protected virtual IFtpFile DoCreateFile(String filename, VirtualFtpSession session) { throw new FtpException(550, String.Format("You cannot create files in a {0}.", this.GetType().Name)); }
public override IFtpFile GetFile(String filename, VirtualFtpSession session) { if (!HasFile(filename)) throw new FtpException(String.Format("A file named \"{0}\" does not exists.", filename)); if (!AllowBrowse(session)) throw new FtpException(550, String.Format("Cannot access file \"{0}\", permission to access files in this folder denied.", filename)); IFtpFile lFile = FileList[filename.ToLower()] as IFtpFile; if (!lFile.AllowRead(session)) throw new FtpException(550, String.Format("Cannot access file \"{0}\", permission to access file denied.", filename)); return lFile; }
get { return fSubFolderList; }
public override void RenameFileOrFolder(String oldFileName, String newFileName, VirtualFtpSession session) { if (HasSubfolder(oldFileName)) { if (!AllowRenameItems(session)) { throw new FtpException(550, String.Format("Cannot rename folder \"{0}\", permission to rename in this folder denied.", oldFileName)); } } else if (HasFile(oldFileName)) { if (!AllowRenameItems(session)) { throw new FtpException(550, String.Format("Cannot rename file \"{0}\", permission to rename in this folder denied.", oldFileName)); } IFtpFile lFile = GetFile(oldFileName, session); if (!lFile.AllowRename(session)) { throw new FtpException(550, String.Format("Cannot rename file \"{0}\", permission to rename file denied.", oldFileName)); } lock (this) { lFile.Name = newFileName; } } else { throw new FtpException(String.Format("A file or folder named \"{0}\" does not exists.", oldFileName)); } }
protected override IFtpFolder DoCreateFolder(string aFolderName, VirtualFtpSession aSession) { lock(this) { if (HasSubfolder(aFolderName))
throw new FtpException(String.Format("Cannot create folder named \"{0}\", a folder with this name already exists.",aFolderName)); if (!AllowMkDir(aSession)) throw new FtpException(550, String.Format("Cannot create folder named \"{0}\", permission denied.",aFolderName));
public override IFtpFolder GetSubFolder(String folder, VirtualFtpSession session) { if (!AllowBrowse(session)) throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to access items in this folder denied.", folder)); IFtpFolder lFolder = SubFolderList[folder.ToLower()] as IFtpFolder; if (lFolder != null && !lFolder.AllowBrowse(session)) throw new FtpException(550, String.Format("Cannot access folder \"{0}\", permission to browse folder denied.", folder)); return lFolder; }
public override void DeleteFile(String filename, VirtualFtpSession session) { if (!HasFile(filename)) throw new FtpException(String.Format("A file named \"{0}\" does not exists.", filename)); if (!AllowDeleteItems(session)) throw new FtpException(550, String.Format("Cannot delete fike \"{0}\", permission to delete from this folder denied.", filename)); IFtpFile lFile = GetFile(filename, session); if (!lFile.AllowDelete(session)) throw new FtpException(550, String.Format("Cannot delete file \"{0}\", permission to delete file denied.", filename)); lock (this) { lFile.Invalidate(); FileList.Remove(filename.ToLower()); } }
public override void DeleteFolder(String folder, Boolean recursive, VirtualFtpSession session) { if (!HasSubfolder(folder)) throw new FtpException(String.Format("A folder named \"{0}\" does not exists.", folder)); if (!AllowDeleteItems(session)) throw new FtpException(550, String.Format("Cannot delete folder \"{0}\", permission to delete from this folder denied.", folder)); IFtpFolder lFolder = GetSubFolder(folder, session); if (!lFolder.AllowDeleteThis(session)) throw new FtpException(550, String.Format("Cannot delete folder \"{0}\", permission to delete folder denied.", folder)); lock (this) { lFolder.Invalidate(); SubFolderList.Remove(folder.ToLower()); } }
public virtual Boolean AllowWrite(VirtualFtpSession session) { if (Invalid) return false; if (session.IsFileAdmin) return true; if (session.Username.ToLower().Equals(OwningUser.ToLower()) && UserWrite) return true; if (WorldWrite) return true; return false; }
protected virtual IFtpFolder DoCreateFolder(String folder, VirtualFtpSession session) { throw new FtpException(550, String.Format("You cannot create subfolders in a {0}.", this.GetType().Name)); }
public override IFtpFile GetFile(String filename, VirtualFtpSession session) { if (!AllowGet(session)) throw new FtpException(550, String.Format("Cannot retrieve file \"{0}\", permission to get files from this folder denied.", filename)); if (!HasFile(filename)) throw new FtpException(550, String.Format("A file named \"{0}\" does not exist.", filename)); return new DiscFile(this, filename, Path.Combine(LocalPath, filename)); }
public override sealed IFtpFile CreateFile(String filename, VirtualFtpSession session) { if (!AllowPut(session)) throw new FtpException(550, String.Format("Cannot create file \"{0}\", permission to upload to this folder denied.", filename)); return DoCreateFile(filename, session); }
protected virtual IFtpFile DoCreateFile(String fileName, VirtualFtpSession session) { throw new FtpException(550, String.Format("You cannot create files in a {0}.", this.GetType().Name)); }
public override IFtpFile CreateFile(String filename, VirtualFtpSession session) { if (!AllowPut(session)) throw new FtpException(550, String.Format("Cannot upload file \"{0}\", permission to upload files to this folder denied.", filename)); if (HasFile(filename)) throw new FtpException(550, String.Format("A file named \"{0}\" already exist.", filename)); return new DiscFile(this, filename, Path.Combine(LocalPath, filename)); }
public override sealed IFtpFolder CreateFolder(String folder, VirtualFtpSession session) { if (!AllowMkDir(session)) throw new FtpException(550, String.Format("Cannot create folder \"{0}\", permission to mkdir in this folder denied.", folder)); return DoCreateFolder(folder, session); }
public override void RenameFileOrFolder(String oldFilename, String newFilename, VirtualFtpSession session) { }
aFolder = Root; aPath = aPath.Substring(1); /* remove / */
public override void DeleteFile(String filename, VirtualFtpSession session) { if (!AllowDeleteItems(session)) throw new FtpException(550, String.Format("Cannot delete file \"{0}\", permission to delete from this folder denied.", filename)); if (!HasFile(filename)) throw new FtpException(550, String.Format("A file named \"{0}\" does not exist.", filename)); File.Delete(Path.Combine(LocalPath, filename)); }