Posted On March 31, 2019

FTP On Upload Email

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 = "[email protected]"
$sendFrom = "[email protected]"
$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 *

Related Post

PowerShell: Nesting Functions Inside Functions

Demo 1: calling a function from within another function function A{ Param($functionToCall) Write-Host "Calling function:…

PowerShell: Regex Examples

# Example 1 Simple 10-digit match $x='123-456-7890' [regex]$regex10Digits='\({0,1}\d{0,1}\){0,1}\-{0,1}(\d{3})' $areaCode=$regex10Digits.Match($x).Groups[1].Value # Example 2 IP Version 4…

PowerShell: Set Hyper-V Cluster Quorum

# setClusterQuorum.ps1 # version 0.01 $clustername=$null $clusterQuorum="\\FILESHERVER007\CLUSTER007" $resetPrior=$false function setClusterQuorum($clusterName,$clusterQuorum,$resetPrior=$false){ # Get clustername, if not…