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