Example #1
0
        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)));
            }
        }
Example #2
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);
                    }
                }
            }
        }