您的位置:首页 > 编程语言 > PHP开发

获取FTP服务器目录的方法

2013-12-12 10:08 197 查看
private string[] GetFileList(string path, string ftpUserID, string ftpPassword, string WRMethods)//上面的代码示例了如何从ftp服务器上获得文件列表
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
try
{
Connect(path, ftpUserID, ftpPassword);

reqFTP.Method = WRMethods;

WebResponse response = reqFTP.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);//中文文件名

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();

return result.ToString().Split('\n');

}

catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);

downloadFiles = null;

return downloadFiles;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐