public SFTPFileAttributes GetFileInformations(string path, bool lstat)
{
CheckStatus();
uint requestId = ++_requestId;
byte[] pathData = _encoding.GetBytes(path);
SFTPPacket packet =
new SFTPPacket(lstat ? SFTPPacketType.SSH_FXP_LSTAT : SFTPPacketType.SSH_FXP_STAT)
.WriteUInt32(requestId)
.WriteAsString(pathData);
bool result = false;
SFTPFileAttributes attributes = null;
_eventHandler.ClearResponseBuffer();
Transmit(packet);
_eventHandler.WaitResponse(
delegate(SFTPPacketType packetType, SSHDataReader dataReader) {
if (packetType == SFTPPacketType.SSH_FXP_STATUS) {
SFTPClientErrorException exception = SFTPClientErrorException.Create(dataReader);
if (exception.ID == requestId) {
throw exception;
}
}
else if (packetType == SFTPPacketType.SSH_FXP_ATTRS) {
uint id = dataReader.ReadUInt32();
if (id == requestId) {
attributes = ReadFileAttributes(dataReader);
result = true; // Ok, received SSH_FXP_ATTRS
return true; // processed
}
}
return false; // ignored
},
_protocolTimeout
);
// sanity check
if (!Volatile.Read(ref result)) {
throw new SFTPClientException("Missing SSH_FXP_ATTRS");
}
return attributes;
}