BCHCAdmin
asked on
WinSCP Scripting Problem
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).
WinSCP_Start.bat
@echo on
"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:password@sft.site.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx.......
# Upload file
put c:\folder\somefile.csv
# Disconnect
#close
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_serv er")
$msg.From = "sender@somesite.org"
$msg.To.Add("receiver@some site.org")
$msg.Subject = "Success/Failure"
$msg.Body = "Success/Failure"
$smtp.Send($msg)
Thank you!
Created a batch file (that is called weekly through Windows Scheduler).
WinSCP_Start.bat
@echo on
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /script=c:\netlearning\nl_
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:password@sft.site.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx.......
# Upload file
put c:\folder\somefile.csv
# Disconnect
#close
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_
$msg.From = "sender@somesite.org"
$msg.To.Add("receiver@some
$msg.Subject = "Success/Failure"
$msg.Body = "Success/Failure"
$smtp.Send($msg)
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ended up using the PowerShell Script to open and read the file but thank you for getting me in the right direction!
ASKER