我不敢说
_________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace test
{
class Program
{
static void Main(string[] args)
{
string path = "ftp://192.168.1.200/services/";
string[] file = GetFileList(path);
Console.ReadLine();
}
public static string[] GetFileList(string path)//上面的代码示例了如何从ftp服务器上获得文件列表
{
string[] downloadFiles;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
ftp.UseBinary = true;
//ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);//如果是匿名登录,则注释掉。
StringBuilder result = new StringBuilder();
try
{
ftp.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = ftp.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);//中文文件名
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
downloadFiles = result.ToString().Split('\n');
}
catch (Exception ex)
{
throw ex;
}
return downloadFiles;
}
}
}