Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WinSCP Scripting Problem

Posted on 2014-12-04
4
Medium Priority
?
341 Views
Last Modified: 2014-12-11
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_server")
$msg.From = "sender@somesite.org"
$msg.To.Add("receiver@somesite.org")
$msg.Subject = "Success/Failure"
$msg.Body = "Success/Failure"
$smtp.Send($msg)


Thank you!
0
Comment
Question by:BCHCAdmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1500 total points
ID: 40481505
Redirect the output of your schedule script to a file, then use findstr to find your success string.  Based on what you find send the mail.
0
 

Author Comment

by:BCHCAdmin
ID: 40486139
Ok - figured out how to write the results to a text file but having issues using the if statement in powershell to make a determination.  I'm writing a "0"on success to results.txt and "1" on failure to file with same name,.  Can you help with powershell commands?
0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 1500 total points
ID: 40486299
>> using the if statement in powershell to make a determination
Do the if in your winscp_start.bat file instead:

findstr /i somestring yourtextfile >nul:
if %ERRORLEVEL% NEQ 0 (
:: put your powershell mail command here
) else (
echo "Everything OK"
)
0
 

Author Closing Comment

by:BCHCAdmin
ID: 40494896
Ended up using the PowerShell Script to open and read the file but thank you for getting me in the right direction!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question