diff --git a/Renci.SshClient/Renci.SshClient/Messages/Sftp/Attributes.cs b/Renci.SshClient/Renci.SshClient/Messages/Sftp/Attributes.cs index 7b9518f9..6069ca84 100644 --- a/Renci.SshClient/Renci.SshClient/Messages/Sftp/Attributes.cs +++ b/Renci.SshClient/Renci.SshClient/Messages/Sftp/Attributes.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Renci.SshClient.Messages.Sftp { - internal class Attributes + public class Attributes { public ulong? Size { get; set; } diff --git a/Renci.SshClient/Renci.SshClient/Messages/Sftp/NameMessage.cs b/Renci.SshClient/Renci.SshClient/Messages/Sftp/NameMessage.cs index c130f325..2d9358eb 100644 --- a/Renci.SshClient/Renci.SshClient/Messages/Sftp/NameMessage.cs +++ b/Renci.SshClient/Renci.SshClient/Messages/Sftp/NameMessage.cs @@ -28,20 +28,9 @@ namespace Renci.SshClient.Messages.Sftp { var fileName = this.ReadString(); var fullName = this.ReadString(); - var attribute = this.ReadAttributes(); + var attributes = this.ReadAttributes(); - // TODO: Complete files info population - files.Add(new SftpFile - { - Name = fileName, - AbsolutePath = fullName, - //Size = attribute.Size, - //UserId = attribute.UserId, - //GroupId = attribute.GroupId, - //AccessedTime = attribute.AccessTime, - //ModifiedTime = attribute.ModifyTime, - Extentions = attribute.Extentions, - }); + files.Add(new SftpFile(fileName, fullName, attributes)); } this.Files = files; } diff --git a/Renci.SshClient/Renci.SshClient/Sftp/SftpFile.cs b/Renci.SshClient/Renci.SshClient/Sftp/SftpFile.cs index ed05ef27..169e06af 100644 --- a/Renci.SshClient/Renci.SshClient/Sftp/SftpFile.cs +++ b/Renci.SshClient/Renci.SshClient/Sftp/SftpFile.cs @@ -1,32 +1,60 @@ using System; using System.Collections.Generic; +using Renci.SshClient.Messages.Sftp; namespace Renci.SshClient.Sftp { public class SftpFile { - public SftpFile() + public SftpFile(string fileName, string fullName, Attributes attributes) { - this.Attributes = new SftpFileAttributes(); - this.CreatedTime = DateTime.MinValue; - this.AccessedTime = DateTime.MinValue; - this.ModifiedTime = DateTime.MinValue; - this.Size = -1; - this.UserId = -1; - this.GroupId = -1; - this.Permissions = -1; - this.Extentions = new Dictionary(); + this.Name = fileName; + + //this.AbsolutePath = fullName; + + if (attributes.Size.HasValue) + this.Size = (int)attributes.Size.Value; + else + this.Size = -1; + + if (attributes.UserId.HasValue) + this.UserId = (int)attributes.UserId.Value; + else + this.UserId = -1; + + if (attributes.GroupId.HasValue) + this.GroupId = (int)attributes.GroupId.Value; + else + this.GroupId = -1; + + if (attributes.Permissions.HasValue) + this.Permissions = (int)attributes.Permissions.Value; + else + this.Permissions = -1; + + if (attributes.AccessTime.HasValue) + this.AccessedTime = attributes.AccessTime.Value; + else + this.AccessedTime = DateTime.MinValue; + + if (attributes.ModifyTime.HasValue) + this.ModifiedTime = attributes.ModifyTime.Value; + else + this.ModifiedTime = DateTime.MinValue; + + //this.CreatedTime = DateTime.MinValue; + + if (attributes.Extentions != null) + this.Extentions = new Dictionary(attributes.Extentions); } public string Name { get; set; } - public string AbsolutePath { get; set; } - - public SftpFileAttributes Attributes { get; set; } + //public string AbsolutePath { get; set; } public string Filename { get; set; } - public DateTime CreatedTime { get; set; } + //public DateTime CreatedTime { get; set; } public DateTime AccessedTime { get; set; } @@ -41,5 +69,10 @@ namespace Renci.SshClient.Sftp public int Permissions { get; set; } public IDictionary Extentions { get; set; } + + public override string ToString() + { + return string.Format("Name {0}, Size {1}, User ID {2}, Group ID {3}, Permissions {4:X}, Accessed {5}, Modified {6}", this.Name, this.Size, this.UserId, this.GroupId, this.Permissions, this.AccessedTime, this.ModifiedTime); + } } }