1

我有一段非常直接的代码可以使用 C# 和 FluentFTP 将一些数据上传到 ftp。

_client = new FtpClient(host);
_client.Credentials = new NetworkCredential(user, password);
await _client.UploadAsync(file, path);

wherehost是一个有效的 ftp 主机名,file是一个字节数组,并且path是 ftp 上的现有远程位置。我可以使用来自 filezilla 等 ftp 客户端的凭据成功登录到我的 ftp,用户已设置所有必需的权限,在调试模式下或执行应用程序文件时一切正常。但是,当应用程序作为 Windows 任务执行时,我的自定义日志文件中不断出现下一个异常:

[ERROR] [00:00:13:01088]: Message: Error while uploading the file to the server. See InnerException for more info.
Source: FluentFTP
Stack Trace:    at FluentFTP.FtpClient.UploadFileInternalAsync(Stream fileData, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown, IProgress`1 progress, CancellationToken token)
   at FluentFTP.FtpClient.UploadAsync(Byte[] fileData, String remotePath, FtpExists existsMode, Boolean createRemoteDir, IProgress`1 progress, CancellationToken token)
   at FileStorage.Ftp.FtpFileStorage.SaveAsync(Byte[] file, String path)
   at Engine.NewStreamers.Program.Main(String[] args) in C:\Dev\...\Program.cs:line 181
Inner Exception: Message: One or more errors occurred. (No such host is known.)
Source: System.Private.CoreLib
Stack Trace:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at FluentFTP.FtpSocketStream.Connect(String host, Int32 port, FtpIpVersion ipVersions)
   at FluentFTP.FtpClient.Connect(FtpSocketStream stream)
   at FluentFTP.FtpClient.Connect()
   at FluentFTP.FtpClient.get_Capabilities()
   at FluentFTP.FtpClient.HasFeature(FtpCapability cap)
   at FluentFTP.FtpClient.FileExistsAsync(String path, CancellationToken token)
   at FluentFTP.FtpClient.UploadFileInternalAsync(Stream fileData, String remotePath, Boolean createRemoteDir, FtpExists existsMode, Boolean fileExists, Boolean fileExistsKnown, IProgress`1 progress, CancellationToken token)
Inner Exception: Message: No such host is known.
Source: System.Private.CoreLib
Stack Trace:    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source)
   at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
   at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult)
   at System.Net.Dns.<>c.<GetHostAddressesAsync>b__25_1(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

仅当应用程序作为 Windows 任务执行时才会发生这种情况。是否有一些可能影响连接的 Windows 任务的防火墙配置?还是其他不明显的问题?

这些是应用于我的 Windows 任务的当前配置: 在此处输入图像描述

其中dmytr是我创建任务的 Windows 管理员用户。

4

0 回答 0