Example #1
0
        void UploadFiles(IProgressReporter ui)
        {
            ui.Maximum = newFiles.Sum(uf => uf.Length);
            foreach (var file in newFiles)
            {
                ui.Caption = "Uploading " + file.RelativePath;

                var ftpRequest = FtpClient.Default.CreateRequest(Combine(UpdateConfig.Standard.RemotePath, file.RemoteUrl));
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

                using (var transform = UpdateChecker.CreateFileEncryptor())

                    using (var requestStream = ftpRequest.GetRequestStream())
                        using (var encryptingStream = new CryptoStream(requestStream, transform, CryptoStreamMode.Write))
                            using (var zipper = new GZipStream(encryptingStream, CompressionMode.Compress, true))

                                using (var fileStream = File.Open(Path.Combine(basePath, file.RelativePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                                    fileStream.CopyTo(zipper, file.Length, ui.ChildOperation());
                                }

                ftpRequest.GetResponse().Close();
            }
        }