public void directoryListSimple()
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
StringBuilder result = new StringBuilder();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("FTP path"));
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Timeout = 100000;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string line = reader.ReadLine();
while (line!=null)
{
DataRow dr = dt.NewRow();
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
if (line != null)
{
dt.Rows.Add(line.ToString());
}
}
Sftpfile.DataSource = dt;
Sftpfile.DataBind();
result.Remove(result.ToString().LastIndexOf('\n'), 1);
//responseDir.Close();
result.ToString().Split('\n');
reader.Close();
response.Close();
}
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
StringBuilder result = new StringBuilder();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("FTP path"));
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Timeout = 100000;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string line = reader.ReadLine();
while (line!=null)
{
DataRow dr = dt.NewRow();
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
if (line != null)
{
dt.Rows.Add(line.ToString());
}
}
Sftpfile.DataSource = dt;
Sftpfile.DataBind();
result.Remove(result.ToString().LastIndexOf('\n'), 1);
//responseDir.Close();
result.ToString().Split('\n');
reader.Close();
response.Close();
}
No comments:
Post a Comment