public void Delete() { var request = FtpDirectory.ToFtpWebRequest(Directory.Location, Path, Directory.Credentials); request.Method = WebRequestMethods.Ftp.DeleteFile; request.UsePassive = Directory.Passive; using (var response = (FtpWebResponse)request.GetResponse()) { Trace.TraceInformation("[FTP] {0} was deleted: {1} {2}".FormatWith(request.RequestUri, response.StatusCode, response.StatusDescription.RemoveFromEnd(Environment.NewLine, StringComparison.Ordinal))); } }
public FileInfo Download(DirectoryInfo local) { if (null == local) { throw new ArgumentNullException("local"); } var request = FtpDirectory.ToFtpWebRequest(Directory.Location, Path, Directory.Credentials); request.Method = WebRequestMethods.Ftp.DownloadFile; request.UsePassive = Directory.Passive; request.UseBinary = true; using (var response = (FtpWebResponse)request.GetResponse()) { using (var stream = response.GetResponseStream()) { if (null == stream) { throw new InvalidOperationException(); } using (var temp = new CurrentTempDirectory()) { var file = temp.Info.ToFile(Name); using (var writer = file.ToWriteStream(FileMode.CreateNew)) { stream.CopyTo(writer); } if (file.Length.IsNot(Size)) { throw new InvalidOperationException(); } Trace.WriteLineIf(Tracing.Is.TraceVerbose, "[FTP] source={0} destination={1}".FormatWith(request.RequestUri.AbsoluteUri, local.FullName)); file.MoveTo(local.ToFile(Name).FullName); file.SetDate(LastModified); return(file); } } } }
public static IEnumerable <FtpFile> Load(Uri location, ICredentials credentials, bool passive, bool secure) { if (null == location) { throw new ArgumentNullException("location"); } Trace.WriteLineIf(Tracing.Is.TraceVerbose, "[FTP] location={0}".FormatWith(location.AbsoluteUri)); var result = new FtpDirectory { Credentials = credentials, Location = location, Passive = passive, Secure = secure, }; return(result.Load()); }
public FtpFile(FtpDirectory directory, string path) { if (null == directory) { throw new ArgumentNullException("directory"); } if (null == path) { throw new ArgumentNullException("path"); } if (path.Trim().IsEmpty()) { throw new ArgumentOutOfRangeException("path"); } Trace.WriteLineIf(Tracing.Is.TraceVerbose, "[FTP] directory={0} path={1}".FormatWith(directory.Location, path)); Directory = directory; Path = path; }