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: Export Exchange Mailboxes

Export 1 mailbox $userAlias="kungfu.panda"$storageUNC="\\FILESHERVER01\Backups\PSTs"# Import Exchange Management PowershellAdd-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;$mailboxRequest=(New-MailboxExportRequest -Mailbox $userAlias -FilePath "$storageUNC\$userAlias.pst").Mailboxfunction monitorCompletion($check){ $migrationStatus=(Get-MailboxExportRequest…

PowerShell: Function to Execute Function Remotely

Function this function that - this quick snippet is to invoke those func things remotely...…

Set File Permissions Recursively – Running on File Server

What problems does this solve? This error: "Failed to enumerate objects in the container. Access…