Applies to: Server!
Version(s): 4.x - 5.x
Warning:    this articles refers to an older version of our software

One of the ready-made script examples that are installed along with Server! shows how to notify someone via email each time a file is uploaded. But what if you wanted to send only one email, at the end of the file transfer session, with the list of all files that were uploaded in such a session?

You can easily do that with 2 simple scripts bound to 2 different event handlers.

First of all, you will need a script bound to the “AfterFileUpload” event handler, to keep the list up to date:

  Session.CustomDataEx.Add(VirtualObjectName); // requires Server! v4+

Then you will need a script bound to the  “OnSFTPClose” and “OnFTPSClose” event handlers, to send out the email when the user disconnects from either protocol:

  MailText: string;  
  MailText := 'SFTP connection came from '+Session.ClientIP+#13#10;
  MailText := MailText+'User was authenticated as '+Session.ReqUsername+#13#10;
  MailText := MailText+#13#10;
  MailText := MailText+'List of all uploaded files during the session:'+#13#10;
  MailText := MailText+Session.CustomDataEx.Text+#13#10;
  MailText := MailText+#13#10;
  MailText := MailText+'Thank you,'+#13#10;
  MailText := MailText+'best regards.'+#13#10;
  MailText := MailText+#13#10;
  MailText := MailText+'Your Server!'+#13#10;
  SendMail('', 'Client session ended', MailText, '');

That's it. Easy and straightforward.