简体   繁体   English

如何使用 ASP.NET web 页面安排在服务器上下载文件

[英]How to schedule downloading of files on server using ASP.NET web page

How to download a file from a web server to another iis server如何将文件从 web 服务器下载到另一个 iis 服务器

eg I have lot of movie files which i want to host on my website例如,我有很多电影文件想在我的网站上托管

the movies are uploaded on other site and I want to grab them on my own site.电影上传到其他网站,我想在我自己的网站上获取它们。

Is it possible to schedule asynchronously downloading of files on server using ASP.NET web page?是否可以使用 ASP.NET web 页面安排在服务器上异步下载文件? I have only FTP access to the web sever as I'm using shared hosting.我只有 FTP 访问 web 服务器,因为我正在使用共享主机。

One things you can do is make use of Window Services ie create Window service and put timer in that will resolve you issue easily.您可以做的一件事是使用Window 服务,即创建 Window 服务并放入计时器,这将轻松解决您的问题。

here is good article: Combine Web and Windows Services to Run Your ASP.NET Code at Scheduled Intervals这是一篇好文章:组合 Web 和 Windows 服务以按计划的时间间隔运行您的 ASP.NET 代码

If you are using shared hosting, scheduling tasks is going to be difficult.如果您使用的是共享主机,那么安排任务将会很困难。 You could implement a service page that performs the download when it is requested.您可以实现一个在请求时执行下载的服务页面。 This page would run on the destination server and request a list of files from the source server and proceed to download those files.此页面将在目标服务器上运行并从源服务器请求文件列表并继续下载这些文件。 The server performs all the work, the client that requests the service page could just get a short log of what the server is doing.服务器执行所有工作,请求服务页面的客户端可以获得服务器正在做什么的简短日志。

Next setup a scheduled task on some other system that invokes the service page at regular intervals.接下来在其他一些系统上设置一个计划任务,该任务会定期调用服务页面。

Since the call to the service page is a very low load on the client you could do that from just about anywhere (a home or office server, a smart router (dd-wrt) you have sitting in closet somewhere or even your smart phone).由于对服务页面的调用在客户端上的负载非常低,您几乎可以从任何地方(家庭或办公室服务器、您坐在壁橱中某处的智能路由器(dd-wrt)甚至您的智能手机)执行此操作) .

Nice bonus of this approach is that you can manually trigger downloading from anywhere by accessing the service page from your browser directly.这种方法的好处是您可以通过直接从浏览器访问服务页面来手动触发从任何地方下载。

On the downside, if the time to complete the downloads exceed the maximum request duration your request is likely to be terminated.不利的一面是,如果完成下载的时间超过最大请求持续时间,您的请求可能会被终止。 You may want to look into asynchronous handlers if that happens.如果发生这种情况,您可能需要查看异步处理程序

You could wire a task to run on every page load or application start (and recycle the app pool regularly), but ASP.NET isn't designed for this type of task.您可以连接一个任务以在每次页面加载或应用程序启动时运行(并定期回收应用程序池),但 ASP.NET 不是为此类任务设计的。

You would be better served building a service or command line tool that can be attached to Task Scheduler to do the downloads every so often.您最好构建一个服务或命令行工具,该工具可以附加到任务计划程序以每隔一段时间进行下载。

1) Add entries to a queue in your ASP.Net application - either MSMQ or database table. 1) 将条目添加到 ASP.Net 应用程序中的队列 - MSMQ 或数据库表。

2) Write a windows service/console application that reads from the queue and processes each item. 2) 编写一个从队列中读取并处理每个项目的 windows 服务/控制台应用程序。

You could also achieve (2) with ScheduledTask in SQL - ton of other ways too no doubt - the key thing is that you put the queue in the middle to provide the disconnection and asychrony.您还可以使用 SQL 中的 ScheduledTask 实现 (2) - 毫无疑问,还有很多其他方式 - 关键是您将队列放在中间以提供断开连接和异步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM