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: Find Hyper-V Host by Guest VM Name

# findVmHostByGuestName.ps1 $vmName='TESTVM' function findVmHostByGuestName($vmName){ try{ Import-Module Hyper-V Import-Module FailoverClusters $allHyperVHosts={(Get-ClusterNode | Where { $_.State…

PowerShell: Get Connected Port by Process Name

# getProcessConnectionPort.ps1 $computerlist=@' SQL1 SQL2 '@ $computernames=@($computerList -split "`n")|%{$_.Trim()} $processname='sqlservr' $state='Established' $results=@() foreach ($computername in…

Windows Cleanup

#Clean Up the WinSxS FolderDism.exe /online /Cleanup-Image /StartComponentCleanup#Clean Up C:\Temp Folderdel c:\temp -Recurse -Force#Cleanup Event…