protected void Page_Load(object sender, EventArgs e) { if (!Request.GetUser().Download) { Response.StatusCode = 401; return; } string path = RouteData.GetRelativePath(), dataPath = FileHelper.GetDataFilePath(path), mime = Request.QueryString["Mime"]; if (string.IsNullOrWhiteSpace(mime)) { mime = FileHelper.GetDefaultMime(dataPath); } try { int timeout; if (!int.TryParse(Request.QueryString["Timeout"], out timeout)) { timeout = 10; } FileHelper.WaitForReady(dataPath, timeout); TransmitFile(FileHelper.GetFilePath(path), mime: mime); } catch (ThreadAbortException) { } }
protected void Page_Load(object sender, EventArgs e) { if (!Request.GetUser().Download) { Response.StatusCode = 401; return; } string path = RouteData.GetRelativePath(), filePath = FileHelper.GetFilePath(path), dataPath = FileHelper.GetDataFilePath(path); if (!File.Exists(dataPath)) { Response.StatusCode = 404; return; } try { int timeout; if (!int.TryParse(Request.QueryString["Timeout"], out timeout)) { timeout = 10; } FileHelper.WaitForReady(dataPath, timeout); TransmitFile(filePath, Path.GetFileName(filePath)); } catch (ThreadAbortException) { } }
protected override void ExecuteCore() { var url = UrlFull; Url = Url; // clear the user account data!!! Save(); var sources = this.GetAllSources().ToArray(); SourceCount = sources.Length; FileLength = sources.Sum(source => new FileInfo(FileHelper.GetFilePath(source)).Length); foreach (var file in sources) { FileHelper.WaitForReady(FileHelper.GetDataFilePath(file)); } var set = new HashSet <string>(new[] { url }); foreach (var file in sources) { CurrentSource = file; Save(); string targetUrl = Path.Combine(url, string.IsNullOrEmpty(BaseFolder) ? file : file.Substring(BaseFolder.Length + 1)), targetDir = Path.GetDirectoryName(targetUrl); FtpWebRequest request; if (!set.Contains(targetDir)) { request = (FtpWebRequest)WebRequest.Create(targetDir); request.Timeout = Timeout.Infinite; request.UseBinary = true; request.UsePassive = true; request.KeepAlive = true; request.Method = WebRequestMethods.Ftp.MakeDirectory; request.GetResponse().Close(); } request = (FtpWebRequest)WebRequest.Create(Path.Combine(url, file)); request.Timeout = Timeout.Infinite; request.UseBinary = true; request.UsePassive = true; request.KeepAlive = true; request.Method = WebRequestMethods.Ftp.UploadFile; using (var src = File.OpenRead(FileHelper.GetFilePath(file))) using (var dst = request.GetRequestStream()) { var byteBuffer = new byte[1048576]; var bytesSent = src.Read(byteBuffer, 0, 1048576); while (bytesSent != 0) { dst.Write(byteBuffer, 0, bytesSent); ProcessedFileLength += bytesSent; Save(); bytesSent = src.Read(byteBuffer, 0, 1048576); } } request.GetResponse().Close(); ProcessedSourceCount++; } Finish(); }
protected override void ExecuteCore() { SevenZipCompressor compressor = null; try { var files = this.GetAllSources().ToList(); foreach (var file in files) { FileHelper.WaitForReady(FileHelper.GetDataFilePath(file)); } long nextLength = 0, nextFile = 0; FileLength = files.Sum(file => new FileInfo(FileHelper.GetFilePath(file)).Length); compressor = new SevenZipCompressor { CompressionLevel = (CompressionLevel)Enum.Parse(typeof(CompressionLevel), TaskXml.GetAttributeValue("compressionLevel"), true) }; switch (Path.GetExtension(RelativePath).ToLowerInvariant()) { case ".7z": compressor.ArchiveFormat = OutArchiveFormat.SevenZip; break; case ".zip": compressor.ArchiveFormat = OutArchiveFormat.Zip; break; case ".tar": compressor.ArchiveFormat = OutArchiveFormat.Tar; break; } var filesStart = Path.GetFullPath(FileHelper.GetFilePath(string.Empty)).Length + 1; compressor.FileCompressionStarted += (sender, e) => { ProcessedSourceCount += nextFile; ProcessedFileLength += nextLength; nextFile = 1; nextLength = new FileInfo(e.FileName).Length; CurrentSource = e.FileName.Substring(filesStart); Save(); }; compressor.CompressFiles(FileHelper.GetFilePath(RelativePath), Path.GetFullPath(FileHelper.GetFilePath(BaseFolder)).Length + 1, files.Select(file => Path.GetFullPath(FileHelper.GetFilePath(file))).ToArray()); ProcessedSourceCount += nextFile; ProcessedFileLength += nextLength; Finish(); } catch (SevenZipException) { if (compressor == null) { throw; } throw new AggregateException(compressor.Exceptions); } }