ProVide can send an automatic email when a file finishes uploading, using a PowerShell script triggered by the Events and Messages module. This example emails the admin every time a new file arrives, including where it came from and where it landed.
Here is the PowerShell script. Save it as a .ps1 file on the server.
# Script parameters passed in by ProVide
param (
[Parameter(Mandatory=$true)][string]$local,
[Parameter(Mandatory=$true)][string]$ftp
)
# Email / SMTP settings
$SMTPServer = "mailserver.domain.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
# Address the email appears to come from
$EmailFrom = "from@domain.com"
# Address that receives the email
$EmailTo = "to@domain.com"
# Subject line
$Subject = "New file"
# Body: everything between @" and "@
$Body = @"
A new file has arrived through $ftp, ending up in $local.
Best regards,
ProVide
"@
# Supply credentials if your SMTP server requires them
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("domain\user", "password")
# Optional: skip SMTP certificate validation (not recommended, see note below)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }
# Send the message
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Trigger the script from ProVide #
You want this to run when a user finishes uploading a file. In the ProVide administration interface, open Events and Messages, then select “OnUploadEnd” from the drop-down menu. Add this line to the message box:
%EXECUTE(Powershell.exe -File "c:\PATH\TO\SCRIPT\SCRIPT.ps1" -local "%LOCAL_FILENAME%" -ftp "%FTP_FILENAME%")%
This tells ProVide to run the PowerShell script at that path when an upload completes, passing the local file path (%LOCAL_FILENAME%) and the path the user uploaded to (%FTP_FILENAME%) into the script’s -local and -ftp parameters.
For a batch-script version of the same idea, see CMD script examples.