Topic "Is there a way to create an IF GOTO command if there was no file found to upload to the FTP site?"

Author Message
somekoreandude
[View user's profile]

Joined: 2015-10-09
Posts: 1
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
@echo
Set mm=%DATE:~4,2%
Set dd=%DATE:~7,2%
Set yyyy=%DATE:~10,4%

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

echo Success
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\SOMEWHERE\SendMailSuccess.ps1'"
goto stage

:error
echo Error!
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\SOMEWHERE\SendMailFailure.ps1'"
goto stage

:stage
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.

pause
exit

Than the script that runs for WINSCP

option batch abort
option confirm off
open sftp://tinkerbell:shakingass@somewhere.com/ -hostkey="ssh-rsa 7777 lalalalallalalalalalallalalalallalalalalalallalalalalla"
cd /
put C:\SOMEWHERE\UPLOAD\ME*.zip
close
exit

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?

Thank you

Thank you.
Guest




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 Error!
pause
exit

:FileChecked

echo Continue with process
pause
exit
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License