1

I have a pretty straight forward piece of code to upload some data to the ftp using C# and FluentFTP.

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

where host is a valid ftp host name, file is a byte array and path is existing remote location on ftp. I can successfully login to my ftp using those credentials from ftp clients like filezilla, user has all required permission set up, everything works fine in debug mode, or when application file is executed. But when application is executed as a windows task I constantly get the next exception in my custom log files:

[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)

This is happening only when application is executed as a Windows Task. Are there some possible firewall configurations for windows tasks that may affect the connection? Or any other non-obvious issues?

Those are the current configurations applied to my windows task: enter image description here

Where dmytr is my windows administrator user that created the task.

Dmytro
  • 16,668
  • 27
  • 80
  • 130

0 Answers0