Posted: 2015-10-09 18:54
I have a windows batch job running that calls WINSCP to connect and upload the file to the FTP site. However the file being uploaded is user generated and complied. So if a scenario happens where the user forgets to create the file and places it in the appropriate folder the script will just assume no files found, and close session. Is there a way to create a IF GOTO or IF ELSE on that condition?
Sample of my code.
Main Batch Job
set path = C:\SOMEWHERE
C:\SOMEWHERE\WinSCP.com /script=C:\SOMEWHERE\WINSCPFTPSITE1.txt > C:\SOMEWHERE\LOGS\UPLOADLOG.txt 2>&1 2>&1
if %ERRORLEVEL% neq 0 goto error
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\SOMEWHERE\SendMailSuccess.ps1'"
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\SOMEWHERE\SendMailFailure.ps1'"
echo Starting transfer from UPLOAD to archive...
xcopy C:\SOMEWHERE\UPLOAD\*.* C:\SOMEWHERE\UPLOAD\ARCHIVE /S /E >> C:\SOMEWHERE\LOGS\UPLOADLOG.txt 2>&1 2>&1
del C:\SOMEWHERE\UPLOAD\*.* /Q /F >> C:\SOMEWHERE\LOGS\UPLOADLOG.txt 2>&1
echo Task Completed.
Than the script that runs for WINSCP
option batch abort
option confirm off
open sftp://tinkerbell:email@example.com/ -hostkey="ssh-rsa 7777 lalalalallalalalalalallalalalallalalalalalallalalalalla"
So when the user forgets to place in the file, the batch job continues but since there is no error it just continues its merry way. I am new to batch scripting and learning for the first time with this assignment. Is there a way to target that condition or result so I can do a IF GOTO or IF ELSE within the batch script or within the WINSCP script?
Posted: 2015-10-09 23:19
I figured it out, I been using the wrong key words to track it down. It is to check for if the file exists in the directory.
Sample of the code at the beginning to check for file.
if exist "C:\SOMEWHERE\UPLOAD\*.zip" goto FileChecked
echo Continue with process
You can post new topics in this forum
And it's free!