/// <summary> /// Gets a list of <see cref="FtpFile"/> objects from the given directory. /// </summary> /// <param name="directory">The server path to get the files from [minus the the host].</param> /// <returns>A list of <see cref="FtpFile"/> from the given directory.</returns> public List <FtpFile> FileList(string directory) { var list = new List <FtpFile>(); string path; var output = GetFtpListOutput(directory); if (directory == string.Empty) { path = string.Empty; } else { path = directory.Substring(0, directory.LastIndexOf('/')); } foreach (string line in output) { var match = LineMatch(line); if (match == null) { throw new ApplicationException("Unable to parse line: " + line); } FtpItem item = BuildItem(match, path); if (item.GetType() == typeof(FtpFile)) { list.Add(( FtpFile )item); } } return(list); }
/// <summary> /// Gets the file size of the specified file. /// </summary> /// <param name="item">The <see cref="FtpFile"/> to get the size of.</param> /// <returns>A long value representing the size of the file.</returns> /// <exception cref="FileNotFoundException"> /// The <paramref name="item"/> argument is null. /// </exception> /// <exception cref="UriFormatException"> /// The <paramref name="item"/> name property is empty. /// </exception> public long FileSize(FtpItem item) { if (item == null) { throw new ArgumentNullException("item", "The FtpItem can not be null"); } if (string.IsNullOrWhiteSpace(item.Name)) { throw new UriFormatException("The FtpItem's Name property can not be empty"); } item.Size = FileSize(item.Path + item.Name); return(item.Size); }
/// <summary> /// Checks whether the file exists on the server or not. /// </summary> /// <param name="item">The <see cref="FtpFile"/> to check.</param> /// <returns><c>true</c> if the file exists, otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentNullException"> /// The <paramref name="item"/> argument is null. /// </exception> public bool FtpItemExists(FtpItem item) { if (item == null) { throw new ArgumentNullException("item", "The FtpItem can not be null"); } if (item.GetType() == typeof(FtpFile)) { return(FtpItemExists(item.Path + item.Name, FtpItemType.File)); } else { return(FtpItemExists(item.Path + item.Name, FtpItemType.Folder)); } }
/// <summary> /// Checks whether the file exists on the server or not. /// </summary> /// <param name="item">The <see cref="FtpFile"/> to check.</param> /// <returns><c>true</c> if the file exists, otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentNullException"> /// The <paramref name="item"/> argument is null. /// </exception> public bool FtpItemExists( FtpItem item ) { if( item == null ) { throw new ArgumentNullException( "item", "The FtpItem can not be null" ); } if( item.GetType() == typeof( FtpFile ) ) { return FtpItemExists( item.Path + item.Name, FtpItemType.File ); } else { return FtpItemExists( item.Path + item.Name, FtpItemType.Folder ); } }
/// <summary> /// Gets the file size of the specified file. /// </summary> /// <param name="item">The <see cref="FtpFile"/> to get the size of.</param> /// <returns>A long value representing the size of the file.</returns> /// <exception cref="FileNotFoundException"> /// The <paramref name="item"/> argument is null. /// </exception> /// <exception cref="UriFormatException"> /// The <paramref name="item"/> name property is empty. /// </exception> public long FileSize( FtpItem item ) { if( item == null ) { throw new ArgumentNullException( "item", "The FtpItem can not be null" ); } if( string.IsNullOrWhiteSpace( item.Name ) ) { throw new UriFormatException( "The FtpItem's Name property can not be empty" ); } item.Size = FileSize( item.Path + item.Name ); return item.Size; }