sparkeh9 / coreftp Goto Github PK
View Code? Open in Web Editor NEWAn FTP library written in C# with no external dependencies
License: MIT License
An FTP library written in C# with no external dependencies
License: MIT License
how can change file name encoding gbk?
I trying open this file ftp://ftp.cetip.com.br/MediaCDI/20170420.txt
` using (var ftpClient = new FtpClient(new FtpClientConfiguration
{
Host = "ftp://ftp.cetip.com.br/"
}))
{
await ftpClient.LoginAsync(); // exception
var files = await ftpClient.ListFilesAsync();
await ftpClient.OpenFileReadStreamAsync("MediaCDI/20170420.txt");
}
`
what is problem of my code?
I dont know how popular this FTP server is, but it returns lines like:
rw-rw-rw- 0 464195454 464195454 Jul 1 2016 G53_EZ_s234_Batch_01.zip
These are not being interpretted correctly.
This library won't work on UWP, and I believe the statement in the readme is inaccurate, as it actually requires .NETStandard >= 1.6.0 and not 1.3.
Since UWP can run up to 1.4, it won't work there.
Hi guy,
I using CoreFtp to login ftp.
My code:
using(var ftpClient = new FtpClient(new FtpClientConfiguration
{
Host = url,
Username = ftpUserID,
Password = ftpPassword,
Port = ftpPort
}))
{
await ftpClient.LoginAsync();
}
But i have exception:
Value cannot be null. Parameter name: remoteEP
Please help me! Thanks so much
when I connect to FTP server it connect to high port (50000+) and stuck when OpenFileReadStreamAsync after login
using (var ftpClient = new FtpClient(new FtpClientConfiguration
{
Host = PrPath,
Username = ftpLogin,
Password = ftpLogin,
BaseDirectory = baseDirectory,
SslProtocols = System.Security.Authentication.SslProtocols.None,
}))
{
var fileinfo = new FileInfo(localpath);
Console.WriteLine("login");
await ftpClient.LoginAsync();
Console.WriteLine("after login");
byte[] existsData;
try
{
using (var readStream = await ftpClient.OpenFileReadStreamAsync(fileUpload))
{
Console.WriteLine("read remote");
existsData = ReadToEnd(readStream);
readStream.Dispose();
Console.WriteLine("after read remote");
}
}
catch (Exception readException)
{
Console.WriteLine("first exception");
Console.WriteLine(readException.Message);
existsData = null;
}
using (var writeStream = await ftpClient.OpenFileWriteStreamAsync(fileUpload))
{
Console.WriteLine("write stream");
var fileReadStream = fileinfo.OpenRead();
if (existsData != null)
{
var existReadStream = new MemoryStream(existsData);
await existReadStream.CopyToAsync(writeStream);
}
await fileReadStream.CopyToAsync(writeStream);
writeStream.Dispose();
fileReadStream.Dispose();
Console.WriteLine("after write stream");
}
ftpClient.Dispose();
System.IO.File.Delete(localpath);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return 1;
it throw a connection attempt fail at XXX.XXX.XXX.XXX:51320 (high port) how can I fix this thank you
I added my certificate in FtpClientConfiguration, but I still receive error.
System.AggregateException: One or more errors occurred. (The remote certificate is invalid according to the validation procedure.) ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
ftpFfg.ClientCertificates.Add(new X509Certificate2(@"C:\mycer.cer"));
Doesnt work on subj.
Hi,
I've got Read permission on the home directory already and I can connect to the server using Filezilla and puTTy, but using CoreFTP in my c# app gives me the above error when I try to connect ftpClient.LoginAsync();
Thank you
I just created a simple console app and added the CoreFTP package but couldn't restore. The error I got was ...
/Users/Matt/Dev/exercises/ftp/ftp.csproj : error NU1605: Detected package downgrade: System.Threading.Tasks from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. [/Users/Matt/Dev/exercises/ftp/ftp.sln]
/Users/Matt/Dev/exercises/ftp/ftp.csproj : error NU1605: ftp (>= 1.0.0) -> CoreFtp (>= 1.3.5) -> System.Net.Security (>= 4.3.0) -> System.Threading.Tasks (>= 4.3.0) [/Users/Matt/Dev/exercises/ftp/ftp.sln]
/Users/Matt/Dev/exercises/ftp/ftp.csproj : error NU1605: ftp (>= 1.0.0) -> CoreFtp (>= 1.3.5) -> System.Threading.Tasks (>= 4.0.11) [/Users/Matt/Dev/exercises/ftp/ftp.sln]
To fix I added the System.Threading.Tasks
package directly (version 4.3.0) and then ran dotnet restore
successfully.
Hi!
I'm trying to use your package CoreFTP but I get a error when it invoque the method LoginAsync():
"Value cannot be null. Parameter name: remoteEP".
The Code:
using (var ftpClient = new FtpClient(new FtpClientConfiguration
{
Host = "ftp://ftp.udc.es",
IgnoreCertificateErrors = true
}))
{
try
{
await ftpClient.LoginAsync();
}
catch (Exception ex)
{
return ex.Message; // ERROR: Value cannot be null. Parameter name: remoteEP
}
....
Any idea? Thanks.
The code always use ANSI encoding while result garbled when use Chinese path, I already fix this problem, but I don't have the push permission, how can I contribute my code?
The server I'm trying to connect with fails to send the "MSIL" feature on the "FEAT" call.
However I know this to be a windows directory.
I'd like to be able to override the feature check with a configuration.
I am using CoreFtp with .net core 1.1.1. When I connect to a remote server and list the folder, the socket appears to remain open, even once the work is done and the FtpClient has been disposed by the using block.
Steps to reproduce, create a new .net core console app and run the following code:
using System;
using CoreFtp;
namespace TestFtp
{
class Program
{
static void Main()
{
var config = new FtpClientConfiguration { Host = "ftp://speedtest.tele2.net/", IgnoreCertificateErrors = true };
for (int i = 0; i < 2048; i++) {
using (var ftpClient = new FtpClient(config)) {
ftpClient.LoginAsync().Wait();
var result = ftpClient.ListFilesAsync().Result;
Console.WriteLine($"{i} = {result.Count}");
}
}
Console.ReadLine(); // Pause at the end
}
}
}
Sockets appear to remain open building up progressively which can be seen, eventually resulting in the loss of the ability to open any more files for the containing process due to reaching the ulimit.
I have confirmed this occurs on 2 separate Mac Book Pros running OSX El Capitan and then tested this on a linux VM (Ubuntu 16.04) and experienced the same failure on all.
Attempting to call CloseFileDataStreamAsync just resulted in an NRE because dataStream was null.
Results can easily be seen in Osx using the Activity Monitor to view the "Open Files and Ports" or by using "lsof -i -p PID" for the dotnet instance.
Example output from failure
94 = 17
95 = 17
Unhandled Exception: System.AggregateException: One or more errors occurred. (Value cannot be null.
Parameter name: remoteEP) ---> System.ArgumentNullException: Value cannot be null.
Parameter name: remoteEP
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
Hi,
is there a way to get the status of the current up-/download?
Like123kb/456kb with 234kb/s? (byte or kilobyte or ...)
Hello, how can I upload a stream?
Hey mate, really nice lib. Works like a charm for ftp. I was wondering if it supports or if you are planning to support SFTP as well. So far I am having trouble connecting to these http://www.sftp.net/public-online-sftp-servers . Unless I am doing something wrong, it seems like it's not supported atm.
This is my code :
using (var ftpClient = new FtpClient(new FtpClientConfiguration { Host = config.FtpHost, Username = config.FtpUsername, Password = config.FtpPassword, Port = config.FtpPort, EncryptionType = FtpEncryption.Explicit, IgnoreCertificateErrors = true }))
Unhandled Exception: System.AggregateException: One or more errors occurred. (Syntax error, command unrecognized.) ---> CoreFtp.I nfrastructure.FtpException: Syntax error, command unrecognized. at CoreFtp.FtpClient.<ConnectDataStreamAsync>d__56.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoreFtp.FtpClient.<OpenFileStreamAsync>d__54.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoreFtp.FtpClient.<OpenFileReadStreamAsync>d__42.MoveNext() --- End of inner exception stack trace ---
Got this by logging into a steam game server via ftp and grabbing all the files and throwing into a log class which has
string Name { get; set; } long Size { get; set; } string Body { get; set; } DateTime LastEdit { get; set; }
the body is made by using a text reader on OpenFileReadStreamAsync
What I got before the error fired was correct.
`
FileSize: 44393 Name: l064_094_095_098_27025_201802240203_002.log Date: 4/9/2018 11:14:00 PM
FileSize: 41393 Name: l064_094_095_098_27025_201802252348_002.log Date: 4/9/2018 11:14:00 PM
FileSize: 47973 Name: l064_094_095_098_27025_201802260042_002.log Date: 4/9/2018 11:14:00 PM
FileSize: 39888 Name: l064_094_095_098_27025_201802270105_002.log Date: 4/9/2018 11:14:00 PM
FileSize: 58090 Name: l064_094_095_098_27025_201803030110_002.log Date: 4/9/2018 11:14:00 PM
FileSize: 49523 Name: l064_094_095_098_27025_201803090133_002.log Date: 4/9/2018 11:14:00 PM
FileSize: 1183 Name: l064_094_095_098_27025_201804091624_002.log Date: 4/10/2018 1:09:00 AM
FileSize: 1183 Name: l064_094_095_098_27025_201804092009_002.log Date: 4/10/2018 5:00:00 AM
FileSize: 1183 Name: l064_094_095_098_27025_201804100000_002.log Date: 4/10/2018 8:49:00 AM
FileSize: 1183 Name: l064_094_095_098_27025_201804100349_002.log Date: 4/10/2018 12:34:00 PM
FileSize: 1183 Name: l064_094_095_098_27025_201804100734_002.log Date: 4/10/2018 4:18:00 PM
FileSize: 1183 Name: l064_094_095_098_27025_201804101118_002.log Date: 4/10/2018 8:02:00 PM
`
Hi there,
I've got a nightly process running that uses your library. Many thanks for making it available.
However, this line https://github.com/sparkeh9/CoreFTP/blob/master/src/CoreFtp/FtpClient.cs#L170
randomly throws an exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at CoreFtp.FtpClient.ChangeWorkingDirectoryAsync(String directory)
at CoreFtp.FtpClient.CreateDirectoryStructureRecursively(IReadOnlyCollection`1 directories, Boolean isRootedPath)
at CoreFtp.FtpClient.OpenFileWriteStreamAsync(String fileName)
For I guess the response does not always contain a double quote.
This is totally random, I upload one file every night (with the same filename format, to the same target ftp directory) and sometimes the log shows the exception and sometimes all goes smoothly.
For now, I retry the upload operation with Polly (http://www.thepollyproject.org/) and has always succeeded at the first retry.
I'm trying to receive hidden files like .htaccess in my code. How can one do that?
Attempting to call ftpClient.LoginAsync() on Linux results in the following exception:
This platform does not support connecting sockets to DNS endpoints via the instance Connect and ConnectAsync methods, due to the potential for a host name to map to multiple IP addresses and sockets becoming invalid for use after a failed connect attempt. Use the static ConnectAsync method, or provide to the instance methods the specific IPAddress desired.
This is the result of https://github.com/dotnet/corefx/issues/8768
Hi,
I'd like to use CoreFTP in my Universal Windows app (UWP).
I created a .NET Core class library and added CoreFTP 1.3.4 via NuGet. Then in my UWP app, I added a reference to the library build (.dll). The UWP project.json looks like this:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
"Newtonsoft.Json": "9.0.1",
"Template10": "1.1.12"
},
"frameworks": {
"uap10.0": { "imports": "netstandard1.4" }
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
I added "imports": "netstandard1.4" because netstandard 1.5 or 1.6 isn't working.
When I try to create a class from the lib, I receive this error:
Could not load file or assembly 'CoreFtp, Version=1.3.4.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
What can I do to use this library in my UWP app?
Thank you for your help!
Currently, CoreFtp uses MLSD
for directory listing retrieval. Unfortunately, not all FTP servers support this command (including “Microsoft FTP Service”, which is the FTP server included in IIS, IIANM). Ideally, CoreFtp should implement more alternative ways to retrieve directory listing, choosing among them dynamically, either by detecting FTP server capabilities (e.g. using FEAT
), or by falling back when an error is detected.
Since I have to list eventually big ftp directories it would be great if
Thanks
Hi,
I'm had trouble on the LoginAsync() Methode.
It takes 20 - 40 Seconds to log in.
using (var ftpClient = new FtpClient(new FtpClientConfiguration
{
Host = ftpSettings.Server,
Port = ftpSettings.Port,
Username = ftpSettings.UserName,
Password = ftpSettings.Password
}))
{
await ftpClient.LoginAsync();
[...]
}
Need to support FTP over SSL
Can you please help me on the below error
Error: Could not to connect socket xx.xx.xx.xx:49285 - No connection could be made because the target machine actively refused it xx.xx.xx.xx:49285
The below is the logic which i have written
string logData = JsonConvert.SerializeObject(log);
_logger.LogInformation(logData);
byte[] byteArray = Encoding.ASCII.GetBytes(logData);
MemoryStream stream = new MemoryStream(byteArray);
var configuration = new FtpClientConfiguration
{
IgnoreCertificateErrors = true,
Host = _host,
//Port = _port,
BaseDirectory = _path,
EncryptionType = FtpEncryption.Implicit
};
if (!string.IsNullOrEmpty(_username))
{
configuration.Username = _username;
configuration.Password = _password;
}
using (var ftpClient = new FtpClient(configuration))
{
ftpClient.Logger = _logger;
_logger.LogInformation("Trying to login");
await ftpClient.LoginAsync();
_logger.LogInformation("Logged in");
using (var writeStream = await ftpClient.OpenFileWriteStreamAsync($"CS-{String.Format("{0:s}", DateTime.Now).Replace(':', '-')}.json"))
{
_logger.LogInformation("Trying to Writing in");
await stream.CopyToAsync(writeStream);
_logger.LogInformation("Write successfully");
}
}
When trying to open a datastream with EncryptionType == FtpEncryption.Explicit in basically get stuck in ActivateEncryptionAsync() while calling SslStream.AuthenticateAsClientAsync(..)
and then fail with this stacktrace
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CoreFtp.Infrastructure.Stream.FtpControlStream.<ActivateEncryptionAsync>d__64.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CoreFtp.Infrastructure.Stream.FtpControlStream.<ConnectStreamAsync>d__60.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CoreFtp.Infrastructure.Stream.FtpControlStream.<OpenDataStreamAsync>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CoreFtp.FtpClient.<ConnectDataStreamAsync>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CoreFtp.FtpClient.<OpenFileStreamAsync>d__50.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at CoreFtp.FtpClient.<OpenFileWriteStreamAsync>d__39.MoveNext()
[FtpClient] Sending command: PWD
Getting Response
Response expected, but no data exists on the socket
257 "/" is your current location
Finished receiving message
[FtpClient] Opening filestream for /dir/file.ext, STOR
[FtpClient] Connecting to a data socket
[FtpClient] Sending command: EPSV
Getting Response
Response expected, but no data exists on the socket
229 Extended Passive mode OK (|||31041|)
Finished receiving message
[FtpSocketStream] Opening datastream
Connecting stream on ftp.server.com:31041
Connecting
[nothing, then crash after what I presume is a server-side timeout]
Any idea? Other detail Could not activate encryption for the connection: The remote certificate is invalid according to the validation procedure.
so I set IgnoreCertificateErrors = true.
I am getting "Could not load file or assembly 'System.Net.Security, Version=4.0.0.0" on my .NET Core 1.1 app (Windows 10 Creators Update, build 15063). What can I do?
Trying to run sample as non async (using task.run) and getting failures.
Hi @sparkeh9
There is a problem with your great package. I got this warning from nuget today. Could you please check it and release new version if needed?
This package has at least one vulnerability with moderate severity. It may lead to specific problems in your project. Try updating the package version.
I am very new to this been using System.Net.FtpWebrequest up until now but don't know where to start with this library. To get a directory listing was pretty simple using this
` Dim pFtpRequest As System.Net.FtpWebRequest
Dim pftpWebResponse As System.Net.FtpWebResponse
Dim srReader As IO.StreamReader
Dim strResult As String
pFtpRequest = CType(FtpWebRequest.Create("ftp://ftp.bom.gov.au/anon/gen/fwo/"), FtpWebRequest)
pFtpRequest.Proxy = New System.Net.WebProxy() 'set empty proxy to avoid http
pFtpRequest.Method = WebRequestMethods.Ftp.ListDirectory
pFtpRequest.KeepAlive = False
pftpWebResponse = CType(pFtpRequest.GetResponse, FtpWebResponse)
srReader = New StreamReader(pftpWebResponse.GetResponseStream)
strResult = srReader.ReadToEnd
srReader.Close()
srReader.Dispose()
pFtpRequest.Abort()
pftpWebResponse.Close()
Console.Write(strResult)`
Could someone show me how to do the equivalent in CoreFTP, its a public ftp site stick "ftp://ftp.bom.gov.au/anon/gen/fwo/" in a browser or windows file explorer and it just works.
I tired several variants of the code below with and without login and password but it just drops out without even hitting the exception handler. Any help would be greatly appreciated.
`CoreFtp.FtpClient ftpClient;
CoreFtp.FtpClientConfiguration ftpConfig;
ftpConfig = new CoreFtp.FtpClientConfiguration();
ftpConfig.BaseDirectory = "/anon/gen/fwo/";
ftpConfig.Host = "ftp.bom.gov.au";
ftpConfig.Username = "anonymous";
ftpConfig.Password = "guest";
ftpConfig.Mode = CoreFtp.Enum.FtpTransferMode.Ascii;
ftpClient = new CoreFtp.FtpClient(ftpConfig);
try
{
await ftpClient.LoginAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}`
Hi.
The last release drops subj, i.e. moves it to the FtpControlStream, but
But i need it to send custom commands, for example GetModificationTime (MDTM) or many other.
Can you share it?
p.s. one more question about:
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.Caching.Memory": "1.0.0",
"Microsoft.Extensions.Logging.Abstractions": "1.0.0"
this is depends from FULL NETStandard.Library
it is really necessary libraries? because in pure .net project (not net.standard) its pull all (20+) net.standard libs.
Hi,
When i try to logout, I am getting many (but not always) an error on the LogoutAsync()
method.
This is my callstack:
Error occured in TryUploadFileAsync 3/10: System.IO.IOException: Unable to read data from the transport connection: Connection timed out. ---> System.Net.Sockets.SocketException: Connection timed out
2017-10-02T12:13:39.674972357Z at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
2017-10-02T12:13:39.674975357Z --- End of inner exception stack trace ---
2017-10-02T12:13:39.674978057Z at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
2017-10-02T12:13:39.674980957Z at CoreFtp.Infrastructure.Stream.FtpControlStream.ReadLine(Encoding encoding, CancellationToken token)
2017-10-02T12:13:39.674983557Z at CoreFtp.Infrastructure.Stream.FtpControlStream.<ReadLines>d__52.MoveNext()
2017-10-02T12:13:39.674986357Z at CoreFtp.Infrastructure.Stream.FtpControlStream.<GetResponseAsync>d__57.MoveNext()
2017-10-02T12:13:39.674989157Z --- End of stack trace from previous location where exception was thrown ---
2017-10-02T12:13:39.674991757Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2017-10-02T12:13:39.674994357Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2017-10-02T12:13:39.674996857Z at CoreFtp.Infrastructure.Stream.FtpControlStream.<SendCommandAsync>d__56.MoveNext()
2017-10-02T12:13:39.675004258Z --- End of stack trace from previous location where exception was thrown ---
2017-10-02T12:13:39.675007558Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2017-10-02T12:13:39.675010058Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2017-10-02T12:13:39.675012758Z at CoreFtp.Infrastructure.Stream.FtpControlStream.<SendCommandAsync>d__55.MoveNext()
2017-10-02T12:13:39.675015358Z --- End of stack trace from previous location where exception was thrown ---
2017-10-02T12:13:39.675017958Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2017-10-02T12:13:39.675020758Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2017-10-02T12:13:39.675023458Z at CoreFtp.Infrastructure.Stream.FtpControlStream.<SendCommandAsync>d__54.MoveNext()
2017-10-02T12:13:39.675033658Z --- End of stack trace from previous location where exception was thrown ---
2017-10-02T12:13:39.675036558Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2017-10-02T12:13:39.675039958Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2017-10-02T12:13:39.675042558Z at CoreFtp.FtpClient.<LogOutAsync>d__35.MoveNext()
2017-10-02T12:13:39.675044958Z --- End of stack trace from previous location where exception was thrown ---
2017-10-02T12:13:39.675047558Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2017-10-02T12:13:39.675050258Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2017-10-02T12:13:39.675052858Z at Ingester.Application.Services.TargetFtp.<TryUploadFileAsync>d__9.MoveNext()
are there any issues known about this?
Do I even need to use a LogOut when using a using
?
below is my code for clearity:
public async Task<Result> UploadAsync(MemoryStream stream, string fileName)
{
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
if (string.IsNullOrWhiteSpace(fileName))
{
throw new ArgumentException(nameof(fileName));
}
using (var client = _ftpClientFactory.Create())
{
var result = await TryUploadFileAsync(client, stream, fileName, 0);
return result;
}
}
private async Task<Result> TryUploadFileAsync(IFtpClient client, Stream stream, string fileName, int currentTry)
{
try
{
_logger.LogDebug("Logging in..");
await client.LoginAsync();
_logger.LogDebug("Logged in.");
_logger.LogDebug($"Working directory: {client.WorkingDirectory}");
if (!string.IsNullOrWhiteSpace(_config.WorkingDirectory) &&
!string.Equals(client.WorkingDirectory, "/" + _config.WorkingDirectory, StringComparison.InvariantCultureIgnoreCase))
{
await client.ChangeWorkingDirectoryAsync(_config.WorkingDirectory);
_logger.LogDebug($"Changed working directory to {client.WorkingDirectory}");
}
using (var writeStream = await client.OpenFileWriteStreamAsync(fileName))
{
stream.Position = 0;
_logger.LogDebug($"Copy file '{fileName}'");
await stream.CopyToAsync(writeStream);
_logger.LogDebug($"File '{fileName}' copied.");
_logger.LogDebug("Logging out");
await client.LogOutAsync();
_logger.LogDebug("Logged out.");
return Result.Ok();
}
}
catch (Exception e)
{
_logger.LogError($"Error occured in TryUploadFileAsync {currentTry}/{NumberOfTriesUpload}: {e}");
if (currentTry < NumberOfTriesUpload)
{
currentTry++;
//many connections/memory, wait a few seconds
await Task.Delay(WaitSeconds * 1000);
return await TryUploadFileAsync(client, stream, fileName, currentTry);
}
return Result.Fail("Number of tries to upload exceeded.");
}
}
Login fail because of FTP Server require SSL connection. But I receive this unclear error msg
System.AggregateException: One or more errors occurred. (End) ---> CoreFtp.Infrastructure.FtpException: End
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.