Script can't connect to multiple accounts on the same remote server
Thanks, Martin. Everything works beautifully!
^
. You have spaces after this line: "put ""Beacon PAM participation in SI CARES.xlsx""" ^
exit
command in the third script.
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="S:\PAM_Reports\WinSCP_UploadScripts\WinSCP.log" /ini=nul ^
/command ^
"open ftpes://sipps.admin_u1:XXXX@ftps.spectramd.com/" ^
"lcd S:\PAM_Reports" ^
"cd ""/sipps_camelot_u01/Camelot of Staten Island/Patient Activation/Reports""" ^
"put ""CAMELOT QA.xlsx""" ^
"put ""CAMELOT Resurvey.xlsx""" ^
"put ""Camelot PAM participation.xlsx""" ^
"exit"
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="S:\PAM_Reports\WinSCP_UploadScripts\WinSCP.log" /ini=nul ^
/command ^
"open ftpes://sipps.admin_u1:XXXX@ftps.spectramd.com/" ^
"lcd S:\PAM_Reports" ^
"cd ""/sipps_beacon_u01/Beacon Christian Community Center/Patient Activation/Reports""" ^
"put ""BEACON CHRISTIAN COMMUNITY CENTER QA.xlsx""" ^
"put ""BEACON CHRISTIAN COMMUNITY CENTER Resurvey.xlsx""" ^
"put ""Beacon PAM participation in SI CARES.xlsx""" ^
"exit"
# STOPS HERE!
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="S:\PAM_Reports\WinSCP_UploadScripts\WinSCP.log" /ini=nul ^
/command ^
"open ftpes://sipps.admin_u1:XXX@ftps.spectramd.com/" ^
"lcd S:\PAM_Reports" ^
"cd ""/sipps_chasi_u1/Community Action of Staten Island/Patient Activation/Reports""" ^
"put ""CHASI PAM participation in SI CARES.xlsx""" ^
"put ""COMMUNITY ACTION OF STATEN ISLAND QA.xlsx""" ^
"put ""COMMUNITY ACTION OF STATEN ISLAND Resurvey.xlsx""" ^
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
# Another account
/command ^
/command
.
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="S:\WinSCP.log" /ini=nul ^
/command ^
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="S:\WinSCP.log" /ini=nul ^
/command ^
"open ftpes://sipps_beacon_u01:XXXXX@ftps.spectramd.com/" ^
"lcd S:" ^
"cd ""/Beacon Christian Community Center/Patient Activation/Reports""" ^
"put ""BEACON CHRISTIAN COMMUNITY CENTER QA.xlsx""" ^
"put ""BEACON CHRISTIAN COMMUNITY CENTER Resurvey.xlsx""" ^
"put ""Beacon PAM participation in SI CARES.xlsx""" ^
"close"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success Beacon
) else (
echo Error
)
# Another account
/command ^
"open ftpes://sipps_camelot_u01:XXX@ftps.spectramd.com/" ^
"lcd S:" ^
"cd ""/sipps_camelot_u01/Camelot of Staten Island/Patient Activation/Reports""" ^
"put ""CAMELOT OF STATEN ISLAND QA.xlsx""" ^
"put ""CAMELOT OF STATEN ISLAND Resurvey.xlsx""" ^
"put ""Camelot PAM participation in SI CARES.xlsx""" ^
"close"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
The connection fails, because your script depends on site, which is not known by the service’s account; or the local account that runs the service does not have a network access.
...
Configure your session completely using open command, using session URL (and raw session settings, if needed), instead of storing site.
- Good practice is to develop your scripts with configuration isolated from GUI.
- Alternatively use INI file instead of registry to store the configuration to make sure the site (and/or other settings) can be accessed by all accounts.