I am playing around with FtpWebRequest and I am wondering how can I format the result?
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("");
ftp.Credentials = new NetworkCredential("", "");
ftp.KeepAlive = true;
ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
WebResponse response = ftp.GetResponse();
StreamReader reader = new StreamReader(response
.GetResponseStream());
string r = reader.ReadLine();
response.Close();
reader.Close();
I get results like this back
09-17-11 01:00AM 942038 my.zip
What would be a good way to parse this into like an object say something like
public Class Test()
{
public DateTime DateCreated? {get; set;}
public int/long Size {get; set;}
public string Name {get; set;}
}
Not sure if I should use a long or int for the size. I am also not sure what the datetime is actually if it is created, or modified or whatever.
var value = "09-17-11 01:00AM 942038 my.zip";
var tokens = value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length > 3)
{
var test = new Test
{
DateCreated = DateTime.ParseExact(tokens[0] + tokens[1], "MM-dd-yyHH:mmtt", CultureInfo.InvariantCulture),
Size = int.Parse(tokens[2]),
Name = tokens[3]
};
// at this stage:
// test.DateCreated = 17/09/2011 01:00AM
// test.Size = 942038
// test.Name = "my.zip"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With