Closed Onway closed 8 years ago
If I simply add a 550 in
var reply = Expect(SendCommand(handle, "LIST", EscapePath(path.ToString())), 125, 150, 425);
I received a NullReferenceException
in
using (var streamReader = new StreamReader(dataStream, ((IFtpStream)dataStream).ProtocolEncoding))
since dataStream
has aborted.
More generally, should we Expect
unsuccessful reply code?
Would it be better if directly throw to user like this:
// class FtpSession
public static FtpReply Expect(FtpReply reply, params int[] codes)
{
if (!codes.Any(code => code == reply.Code))
{
if (reply.Code.Class == FtpReplyCodeClass.Connections)
throw new IOException();
else
throw new UnexcpetedReplyException(reply);
}
return reply;
}
// in some FtpClient methods
using (var dataStream = OpenDataStream(handle, FtpTransferMode.Binary))
{
try
{
Expect(SendCommand(handle, "LIST", EscapePath(path.ToString())), 125, 150);
}
catch
{
Abort(dataStream);
throw;
}
// read from dataStream
}
:grin:
Thanks for suggestion, I'll take a look at it soon.
Fixed in version 1.6
After replied 550, the server would not give the second one, then FtpStream.Release(true) will be blocking.