我的类继承自FluentFTP,我创建了一个这样的类。我需要在这个类中创建一个名为Read的函数。read函数的目的是通过逐行读取我从FTP读取的文件内容来向我返回一个字符串。稍后我将处理旋转的字符串。在FluentFTP中有解决这个问题的方法吗?Ff没有,我该如何创建函数?
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);
}
}我不能这样写,因为我写的Client来自FTP。因为我在前面的代码中从SFTP派生了它,所以我想使用与它类似的代码片段,但在FluentFTP中没有这样的代码片段。如何在Read函数中执行操作?
在另一个文件中,我想这样命名它。
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);
}发布于 2021-11-11 19:01:20
要使用FluentFTP将文件读入字符串,可以使用FtpClient.Download method,它可以将文件内容写入Stream或byte[]数组。下面的示例使用后者。
if (!client.Download(out byte[] bytes, "/remote/path/file.txt"))
{
throw new Exception("Cannot read file");
}
string contents = Encoding.UTF8.GetString(bytes);https://stackoverflow.com/questions/69933225
复制相似问题