Script for copy files, move if succes and create log
Hello All,
I have a problem with creating a script. It should copy local files to remote server and if success move to another folder and create a log with a format: filename Done!
I used some different script based on windows bash and created two scripts.
First:
This code working fine but.... If broken connection try to reconnect and copy files. There are some issues with this. There is not possible to create own format log. If no connection trying to reconnect and start puting all files again. If no success cannot move files to another directory.
Second one:
This one is almost working as I need but to copy each file in directory I need to start a new session of winscp and create a new connection.
Do you have any idea how to combine these scripts to make one or how to create script with functionality what I want?
Best regards
Grzegorz
I have a problem with creating a script. It should copy local files to remote server and if success move to another folder and create a log with a format: filename Done!
I used some different script based on windows bash and created two scripts.
First:
@echo off SETLOCAL set file=x:\mypathtolog\*.log set TRIES=10 set INTERVAL=30 set REMOTE_PATH=/remotepath/ :retry "C:\Program Files (x86)\WinSCP\WinSCP.com" ^ /log="winsclogpath\!Y!M!D_Log.log" /ini=nul ^ /command ^ "open ftp://myftpip/" ^ "put *.* %REMOTE_PATH%" ^ "exit" set WINSCP_RESULT=%ERRORLEVEL% if %WINSCP_RESULT% equ 0 ( echo Upload succeeded, moving local files move mylocalpath\*.* mylocalpathdone\ exit /b 0 ) else ( set /A TRIES=%TRIES%-1 if %TRIES% gtr 1 ( echo Failed, retrying in %INTERVAL% seconds... timeout /t %INTERVAL% goto retry ) else ( echo Failed, aborting exit /b 1 ) ) exit /b %WINSCP_RESULT%
This code working fine but.... If broken connection try to reconnect and copy files. There are some issues with this. There is not possible to create own format log. If no connection trying to reconnect and start puting all files again. If no success cannot move files to another directory.
Second one:
@echo off
SETLOCAL
SET TRIES=10
SET INTERVAL=30
SET REMOTE_PATH=/remotepath/
SET MyLogOK=mylogpath\MyLogOK.txt
SET MyLogERR=myerrorlogpath\MyLogOK.txt
SET LOCAL_PATH=localpath
SET LOCAL_PATH_DONE=localpathdone\
set file=%LOCAL_PATH%\*.log
FOR %%i IN ("%file%") DO (
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="pathtolog\log\!Y!M!D_Log.log" /ini=nul ^
/command ^
"open ftp://ftpserverip" ^
"put %%~di%%~pi%%~ni%%~xi %REMOTE_PATH%" ^
"exit"
if %ERRORLEVEL% equ 0 (
echo Upload succeeded, moving local files
move %%~di%%~pi%%~ni%%~xi %LOCAL_PATH_DONE%%%~ni%%~xi
echo %%~ni%%~xi DONE! >> %MyLogOK%
) else (
echo %%~ni%%~xi ERROR! >> %MyLogERR%
)
)
exit /b 0This one is almost working as I need but to copy each file in directory I need to start a new session of winscp and create a new connection.
Do you have any idea how to combine these scripts to make one or how to create script with functionality what I want?
Best regards
Grzegorz