FTP client in .netcore

Can I upload files / file list via FTP using netcoreapp1.0 ?

I know I can use FtpWebRequest or FluentFTP if I am aiming for a complete .net45 structure.

My solution, however, is based on the .net 1.6 standard, and I do not want to maintain a complete structure just to have FTP.

+11
source share
5 answers

FtpWebRequest is now included in .NET Standard 2.0

FluentFTP is also compatible with the latest .net 2.0 standard

+8
source

There are no built-in FTP features for netcoreapp1.0 or netstandard1.6. FtpWebRequest will return to netstandard2.0.

+6
source

FluentFTP now supports the .NET kernel / .NET 1.6 standard. If you encounter problems, please add the problem to the tracker and we will work on it.

+6
source

FtpWebRequest now supported in .NET Core 2.0. View GitHub repository

Usage example:

 public static byte[] MakeRequest( string method, string uri, string username, string password, byte[] requestBody = null) { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri); request.Credentials = new NetworkCredential(username, password); request.Method = method; //Other request settings (eg UsePassive, EnableSsl, Timeout set here) if (requestBody != null) { using (MemoryStream requestMemStream = new MemoryStream(requestBody)) using (Stream requestStream = request.GetRequestStream()) { requestMemStream.CopyTo(requestStream); } } using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) using (MemoryStream responseBody = new MemoryStream()) { response.GetResponseStream().CopyTo(responseBody); return responseBody.ToArray(); } } 

Where the value of the method parameter is set as a member of System.Net.WebRequestMethods.Ftp .

See also FTP examples.

+3
source

You can try using the FtpWebRequest method.

Sample:

 public static byte[] DownloadFile(string url, string filePath, string user, string password) { var ftpServerUrl = string.Concat(url, filePath); var request = (FtpWebRequest) WebRequest.Create(ftpServerUrl); request.Method = WebRequestMethods.Ftp.DownloadFile; request.Credentials = new NetworkCredential(user,password); using (var response = (FtpWebResponse) request.GetResponse()) using (var responseStream = response.GetResponseStream()) using (var memoryStream = new MemoryStream()) { responseStream?.CopyTo(memoryStream); return memoryStream.ToArray(); } } 

Remember that ftpServerUrl must be a valid uri path containing the file path. e.g. ftpServerUrl = "ftp://ftp.server/targetfile.txt"

+2
source

Source: https://habr.com/ru/post/1012323/


All Articles