mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
Populate and correct SFTP file attributes
This commit is contained in:
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Renci.SshClient.Messages.Sftp
|
||||
{
|
||||
internal class Attributes
|
||||
public class Attributes
|
||||
{
|
||||
public ulong? Size { get; set; }
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<string, string>();
|
||||
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<string, string>(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<string, string> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user