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)); } }
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()); } }
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)); }
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; }
/// <summary> /// Compares directory or file to another. /// </summary> /// <param name="obj">An <see cref="Object"/> to compare against.</param> /// <returns>An <see cref="Int32"/> that represents the result of the comparison. 1 - object is greater than, 0 - object is equal to, -1 - object is less than.</returns> public int CompareTo(object obj) { if (Equals(obj, null)) { return(1); } else { IFtpFile file = obj as IFtpFile; if ((object)file == null) { return(1); } else { return(CompareTo(file)); } } }
/// <summary> /// Compares directory or file to another. /// </summary> /// <param name="obj">An <see cref="Object"/> to compare against.</param> /// <returns>An <see cref="Int32"/> value representing the result. 1 - obj is greater than, 0 - obj is equal to, -1 - obj is less than.</returns> public int CompareTo(object obj) { if (object.Equals(obj, null)) { return(1); } else { IFtpFile file = obj as IFtpFile; if ((object)file == null) { return(1); } else { return(((IComparable <IFtpFile>) this).CompareTo(file)); } } }
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); }
int IComparable <IFtpFile> .CompareTo(IFtpFile other) { // Files are sorted by name return(string.Compare(m_name, other.Name, m_parent.CaseInsensitive)); }
int IComparable <IFtpFile> .CompareTo(IFtpFile other) { // Directories are sorted by name return(string.Compare(m_name, other.Name, m_caseInsensitive)); }