FTP On Upload Email

# Connection details
# If your SMTP server does not support SSL, remove the -UseSSL parameter from the Send-MailMessage cmdlet
$smtpServer = "smtp.kimconnect.com"
$port = 465
$username = "username"

# Storing passwords in files as plain text is not recommended. Use the following command to generate an encoded secure string from your password:
# ConvertTo-SecureString "password" -AsPlainText -Force | ConvertFrom-SecureString
# Replace the line below with $password = ConvertTo-SecureString "SecureStringReturnedFromTheAboveCommand"
$password = ConvertTo-SecureString "password" -AsPlainText -Force

# Email header
$sendTo = "to@kimconnect.com"
$sendFrom = "from@kimconnect.com"
$subject = "File uploaded to Bitvise SSH Server"

# Email body
$uploadEndBy = "The file was closed by session teardown and is likely to be incomplete."
If ($env:SSHUPLOADENDBY -eq "CLIENT") {
$uploadEndBy = "The file was closed by the client."
}

$uploadNew = "An existing file was used."
If ($env:SSHUPLOADNEW) {
$uploadNew = "A new file was created."
}

$uploadResize = ""
If ($env:SSHUPLOADRESIZE) {
$uploadResize = "At least one file resize request by the client was successfully completed, or the existing file was truncated when opened."
}

$uploadUser = ""
If ($env:VIRTUSER) {
$uploadUser = "virtual account " + $env:VIRTUSER
} Else {
$uploadUser = "Windows account " + $env:SSHWINUSERDOMAIN + "\" + $env:SSHWINUSER
}

$message = @"
New file uploaded by $uploadUser
Client address: $env:SSH_CLIENT
Local path of file: $env:SSHUPLOADFILE
Number of bytes written: $env:SSHUPLOADBYTES
$uploadEndBy
$uploadNew
$uploadResize
"@

# Preparing credential and sending the e-mail
$credential = New-Object System.Management.Automation.PSCredential ($username, $password)
Send-MailMessage -SmtpServer $smtpServer -Port $port -UseSSL -Credential $credential -To $sendTo -From $sendFrom -Subject $subject -Body $message

Leave a Reply

Your email address will not be published. Required fields are marked *