gpt4 book ai didi

c# - 获取文件列表

转载 作者:太空宇宙 更新时间:2023-11-03 11:15:13 29 4
gpt4 key购买 nike

我正在尝试获取 FTP 文件夹中的文件列表。当我在本地运行代码时,代码可以正常工作,但在部署它时,我开始接收 html 而不是文件名

ArrayList fName = new ArrayList();
try
{
StringBuilder result = new StringBuilder();

//create the directory
FtpWebRequest requestDir =
(FtpWebRequest) FtpWebRequest.Create(new Uri(directory));
requestDir.Method = WebRequestMethods.Ftp.ListDirectory;
requestDir.Credentials = new NetworkCredential(FTP_USER_NAME, FTP_PASSWORD);
requestDir.UsePassive = true;
requestDir.UseBinary = true;
requestDir.KeepAlive = false;
requestDir.Proxy = null;
FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse();
Stream ftpStream = response.GetResponseStream();
StreamReader reader = new StreamReader(ftpStream, Encoding.ASCII);

while (!reader.EndOfStream)
{
fName.Add(reader.ReadLine().ToString());
}

response.Close();
ftpStream.Close();
reader.Close();

最佳答案

您可以尝试使用 GetFileName

Uri uri = new Uri(hreflink);
string filename = Path.GetFileName(uri.LocalPath);

关于c# - 获取文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12836297/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com