log.debug("Sending SSH_FXP_READDIR...");
sendMessage(Packet.SSH_FXP_READDIR, req_id, tw.getBytes());
byte[] resp = receiveMessage(34000);
TypesReader tr = new TypesReader(resp);
int t = tr.readByte();
listener.read(Packet.forName(t));
int rep_id = tr.readUINT32();
if (rep_id != req_id)
{
throw new IOException("The server sent an invalid id field.");
}
if (t == Packet.SSH_FXP_NAME)
{
int count = tr.readUINT32();
log.debug("Parsing " + count + " name entries...");
while (count > 0)
{
SFTPv3DirectoryEntry dirEnt = new SFTPv3DirectoryEntry();
dirEnt.filename = tr.readString(charsetName);
dirEnt.longEntry = tr.readString(charsetName);
listener.read(dirEnt.longEntry);
dirEnt.attributes = readAttrs(tr);
files.add(dirEnt);
log.debug("File: '" + dirEnt.filename + "'");
count--;
}
continue;
}
if (t != Packet.SSH_FXP_STATUS)
{
throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
}
int errorCode = tr.readUINT32();
if (errorCode == ErrorCodes.SSH_FX_EOF)
{
return files;
}
String errorMessage = tr.readString();
listener.read(errorMessage);
throw new SFTPException(errorMessage, errorCode);
}
}