c#获取服务器上文件的大小,C#获取FTP服务器上的文件及文件夹属性

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Net;

using System.IO;

using System.Xml;

using System.Net.Sockets;

namespace 排版

{

class Program

{

static void Main(string[] args)

{

Uri uri = new Uri("ftp://127.0.0.1");

FtpWebRequest ftpreq = (FtpWebRequest)WebRequest.Create(uri);

ftpreq.Credentials = new NetworkCredential("hello", "123");

ftpreq.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

//ftpreq.Method = WebRequestMethods.Ftp.ListDirectory;

FtpWebResponse ftpres = (FtpWebResponse)ftpreq.GetResponse();

Stream stream = ftpres.GetResponseStream();

StreamReader reader = new StreamReader(stream,System.Text.Encoding.UTF8);

string line = reader.ReadLine();

StringBuilder result = new StringBuilder();

while (line != null)

{

result.AppendLine(line);

Console.WriteLine(line);

line = reader.ReadLine();

}

Console.ReadKey();

}

}

}

你可能感兴趣的:(c#获取服务器上文件的大小)