my class inherits from FluentFtp and I have created a class like this. I need to create a function called Read in this class. The purpose of the read function is to return a string to me by reading the contents of the files I have read from the ftp line by line. I'll process the rotating string later. Is there a value for this in FluentFtpde? if there is none, how should I create a function
using FluentFTP;
public class CustomFtpClient : FtpClient
{
public CustomFtpClient(string host, int port, string username, string password) : base(host, port, username, password)
{
Client = new FtpClient(host, port, username, password);
Client.AutoConnect();
}
private FtpClient Client { get; }
public string ReadFile(string remoteFileName)
{
Client.BufferSize = 4 * 1024;
return Client.ReadAllText(remoteFileName);
}
I can't write like this because the Client I'm writing comes from Ftp. Since I derived it from Sftp in my previous codes, I wanted to use a similar code slice to it, but there is no such code slice in FluentFtp How should I perform an operation in the Read Function .
In another file, I want to call it like this.
CustomFtpClient = new CustomFtpClient(ftpurl, 21, ftpusername, ftppwd);
var listedfiles = CustomFtpClient.GetListing("inbound");
var onlyedifiles = listedfiles.Where(z =>
z.FullName.ToLower().Contains(".txt") || z.FullName.ToLower().Contains("940")).ToList();
foreach (var item in onlyedifiles)
{
//var filestr = CustomFtpClient.ReadFile(item.FullName);
but I couldn't do it because it was a mistake.
var filestr = CustomFtpClient.ReadFile(item.FullName);
To read file to a string using FluentFTP, you can do:
if (!client.Download(out byte[] bytes, "/remote/path/file.txt"))
{
throw new Exception("Cannot read file");
}
string contents = Encoding.UTF8.GetString(bytes);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.