public void ctor() { using (var directory = new CurrentTempDirectory()) { Assert.NotNull(directory); } }
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; } } } }