WinSCP Scripting Problem
Posted on 2014-12-04
I am using WinSCP script to SFTP a file. I have the code working to upload the file but I'm wanting to send a confirmation email upon success/failure of the transfer. Here is what I've done so far:
Created a batch file (that is called weekly through Windows Scheduler).
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /script=c:\netlearning\nl_upload.txt
Calls nl_upload.txt script file (contents here)
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect to SFTP server using a password
open sftp://username:email@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx.......
# Upload file
This works correctly and the file is uploaded. how do I then grab a 'successs/failure' parameter to send via email? I was thinking about grabbing the parameter and then passing it to PowerShell to a script I wrote to send an email.... (or is there an easier way....
powershell script to send email:
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient("smtp_email_server")
$msg.From = "firstname.lastname@example.org"
$msg.Subject = "Success/Failure"
$msg.Body = "Success/Failure"