Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3k views
in .NET FTP by
Hi

I noticed that the TransferComplete event is firing prior to running ValidateTransfer.

This caused errors for me as I was assuming when the transfer was complete I could close the ftp connection, however attempting to do so causes exceptions as 'ValidateTransfer' (part of the put method) requires the connection to still be open.

I understand most people will probably want to write synchronous code such as ;
TransferFile
{
  FtpClient ftp = new FtpClient()
  ftp.login();
  ftp.put();
  ftp.quit();
}


But I needed to seperate this out to;
OnDialupConnected
{
  ftp.login();
  ftp.put();
}

On FtpTransferComplete
{
   ftp.quit();
   CloseDialupConnection();
}


As an enhancement / minor bug-fix I would request that the TransferComplete event is only fired /after/ ValidateTransfer.

As a workaround I added an event to ValidateTransfer that I can subscribe to.

/// <summary>
/// Event for notifying transfer complete and validated
/// </summary>
public virtual event EventHandler TransferValidated;


public virtual void ValidateTransfer()
{            
    CheckConnection(true);
    
    // check the control response
    string[] validCodes = new string[]{"225", "226", "250", "426", "450"};
    FTPReply reply = control.ReadReply();
    
    // permit 426/450 error if we cancelled the transfer, otherwise
    // throw an exception
    string code = reply.ReplyCode;
    if ((code.Equals("426") || code.Equals("450")) && !cancelTransfer)
        throw new FTPException(reply);
    
    lastValidReply = control.ValidateReply(reply, validCodes);

      if (TransferValidated != null)   TransferValidated(this, new EventArgs());

}


Thanks
Paul

1 Answer

0 votes
by (161k points)
A good point - we'll take a look and will most likely change the event so it is fired after the entire transfer sequence is completed.

Hi

I noticed that the TransferComplete event is firing prior to running ValidateTransfer.

Categories

...