简体   繁体   English

使用任务计划程序时“WebClient 请求期间发生异常”

[英]"An exception occurred during a WebClient request" when using the Task Scheduler

I have a console app that downloads certain files from an FTP server.我有一个控制台应用程序,可以从 FTP 服务器下载某些文件。 I'm using WebClient to do this like so:我正在使用WebClient这样做:

var cred = new NetworkCredential(user, password);
var downloadRequest = new WebClient();
downloadRequest.Credentials = cred;
downloadRequest.DownloadFile(host + FileName, target + FileName);

This works perfectly when I run the app normally.当我正常运行应用程序时,这非常有效。 However, I need to run this in the weekend so I have had Task Scheduler run it on Sunday.但是,我需要在周末运行它,所以我让任务计划程序在周日运行它。 But when I do, I always get this error in my log:但是当我这样做时,我的日志中总是会出现这个错误:

An exception occurred during a WebClient request

When I rerun it manually, it works perfectly.当我手动重新运行它时,它可以完美运行。 Is there anything I'm overlooking?有什么我忽略的吗?

This could help others looking for solution.这可以帮助其他人寻找解决方案。

I believe this line:我相信这条线:

downloadRequest.DownloadFile(host + FileName, target + FileName);

is doing the trick.正在做的伎俩。 Somehow it just doesn't recognize the FileName (second parameter).不知何故,它只是无法识别 FileName(第二个参数)。

What worked for me is, I changed the above line to the following:对我有用的是,我将上面的行更改为以下内容:

downloadRequest.DownloadFileAsync(new Uri(host + FileName), target + FileName);

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

相关问题 WebClient请求期间发生异常 - Exception occurred during a WebClient request Windows服务WebClient请求期间发生异常 - Windows Service An exception occurred during a WebClient request 使用webclient下载大文件时出现“ WebClient请求期间发生异常” - Getting “An exception occurred during a WebClient request” while download the large file using webclient 为什么从网站下载图像时出现异常:WebClient请求期间发生异常? - Why when downloading images from a website im getting exception: An exception occurred during a WebClient request? 使用C#ASP.NET时,“WebClient请求期间发生异常” - 'An exception occurred during a WebClient request" while using C# ASP.NET WebClient请求期间发生异常。 在Windows Phone中 - An exception occurred during a WebClient request. in windows phone 当前Web请求“Ненайденуказанныймодуль”的执行期间发生未处理的异常 - An unhandled exception occurred during the execution of the current web request, “Не найден указанный модуль” 当前Web请求执行期间发生未处理的异常 - An unhandled exception occurred during the execution of the current web request 上传值时出现WebClient异常 - WebClient exception when UploadValues 使用Process.Start()和Windows Task Scheduler的异常 - Exception using Process.Start() and Windows Task Scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM