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

SQL Failover (Simple Method)

$servers="SQL01","SQL02","SQL03"; # Dynamic Credential method 1 $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…

Terminal Service Auditing – Generate Report of RDP Sessions with Certain Login Dates

# getLoginEvents.ps1 function getLoginEvents{ param( $computername=$env:computername, $daysLimit=30 ) $ErrorActionPreference='stop' try{ $logins=Get-WinEvent -ComputerName $ComputerName -LogName "Microsoft-Windows-TerminalServices-LocalSessionManager/Operational"|…

PowerShell: Grant Current User Full Access to File or Folder

# Grant Current User Full Access to Object $object='C:\temp' $acl=Get-Acl $object $currentUser=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name $grantAccess=New-Object System.Security.AccessControl.FileSystemAccessRule("$currentUser","FullControl","Allow") $acl.AddAccessRule($grantAccess)…