@martin: Yes, I tried doing this without change in result: 1) Manually running batch script works and outputs log 2) Running batch script from Task Scheduler results in 0x1 from WinSCP (remaining batch script functions execute correctly)
@echo off
set rxfolder=C:\Localdirectory
set filetypes=*.xml
set backupcmd=move /y
echo %date% %time% >> foc-autotask.log 2>&1
echo ### SFTP files... >> foc-autotask.log 2>&1
"C:\Program Files (x86)\WinSCP\WinSCP.com" /log=%rxfolder%\!T!S.log /command "option batch abort" "option confirm off" "open sftp://<unm>:<pwd>@<ftp-server>" "put C:\Localdirectory\*.xml /remotedirectory/" "exit"
echo ### Backing up Rx orders... >> foc-autotask.log 2>&1
%backupcmd% "%rxfolder%\%filetypes%" "%rxfolder%\backup\"
echo Backup Complete!------------------- >> foc-autotask.log 2>&1
exit
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 WinSCP Version 5.5.1 (Build 3970) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2014-02-28 10:57:57.689 Configuration: C:\Program Files (x86)\WinSCP\WinSCP.ini
. 2014-02-28 10:57:57.689 Local account: <windows-admin>
. 2014-02-28 10:57:57.689 Working directory: C:\RO\OrderXML
. 2014-02-28 10:57:57.689 Process ID: 7524
. 2014-02-28 10:57:57.689 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" /console=551 /consoleinstance=_4504_607 "/log=C:\RO\OrderXML\!T!S.log" "/command" "option batch abort" "option confirm off" "open sftp://<unm>:<pwd>@<ftp-server>" "put C:\LocalDirectory\*.xml /remotedirectory/" "exit"
. 2014-02-28 10:57:57.689 Time zone: Current: GMT-6, Standard: GMT-6, DST: GMT-5, DST Start: 3/9/2014, DST End: 11/2/2014
. 2014-02-28 10:57:57.689 Login time: Friday, February 28, 2014 10:57:57 AM
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 Script: Retrospectivelly logging previous script records:
> 2014-02-28 10:57:57.689 Script: option batch abort
< 2014-02-28 10:57:57.689 Script: batch abort
> 2014-02-28 10:57:57.689 Script: option confirm off
< 2014-02-28 10:57:57.689 Script: confirm off
> 2014-02-28 10:57:57.689 Script: open sftp://<unm>***@<ftp-server>
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 Session name: <unm>@<ftp-server> (Ad-Hoc site)
. 2014-02-28 10:57:57.689 Host name: <ftp-server> (Port: 22)
. 2014-02-28 10:57:57.689 User name: <unm> (Password: Yes, Key file: No)
. 2014-02-28 10:57:57.689 Tunnel: No
. 2014-02-28 10:57:57.689 Transfer Protocol: SFTP
. 2014-02-28 10:57:57.689 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2014-02-28 10:57:57.689 Proxy: none
. 2014-02-28 10:57:57.689 Send buffer: 262144
. 2014-02-28 10:57:57.689 SSH protocol version: 2; Compression: No
. 2014-02-28 10:57:57.689 Bypass authentication: No
. 2014-02-28 10:57:57.689 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2014-02-28 10:57:57.689 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2014-02-28 10:57:57.689 SSH Bugs: A,A,A,A,A,A,A,A,A,A
. 2014-02-28 10:57:57.689 Simple channel: Yes
. 2014-02-28 10:57:57.689 Return code variable: Autodetect; Lookup user groups: A
. 2014-02-28 10:57:57.689 Shell: default
. 2014-02-28 10:57:57.689 EOL: 0, UTF: 2
. 2014-02-28 10:57:57.689 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2014-02-28 10:57:57.689 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2014-02-28 10:57:57.689 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2014-02-28 10:57:57.689 Cache directory changes: Yes, Permanent: Yes
. 2014-02-28 10:57:57.689 DST mode: 1; Timezone offset: 0h 0m
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 Looking up host "<ftp-server>"
. 2014-02-28 10:57:57.689 Connecting to <ftp-server> port 22
. 2014-02-28 10:57:57.736 Server version: SSH-2.0-OpenSSH_4.3
. 2014-02-28 10:57:57.736 Using SSH protocol version 2
. 2014-02-28 10:57:57.736 We claim version: SSH-2.0-WinSCP_release_5.5.1
. 2014-02-28 10:57:57.751 Doing Diffie-Hellman group exchange
. 2014-02-28 10:57:57.829 Doing Diffie-Hellman key exchange with hash SHA-1
. 2014-02-28 10:57:58.485 Verifying host key rsa2 *****
. 2014-02-28 10:57:58.485 Host key matches cached key
. 2014-02-28 10:57:58.485 Host key fingerprint is:
. 2014-02-28 10:57:58.485 ssh-rsa 2048 ****
. 2014-02-28 10:57:58.485 Initialised AES-256 SDCTR client->server encryption
. 2014-02-28 10:57:58.485 Initialised HMAC-SHA1 client->server MAC algorithm
. 2014-02-28 10:57:58.485 Initialised AES-256 SDCTR server->client encryption
. 2014-02-28 10:57:58.485 Initialised HMAC-SHA1 server->client MAC algorithm
! 2014-02-28 10:57:58.563 Using username "<unm>".
. 2014-02-28 10:57:58.578 Prompt (7, SSH password, , &Password: )
. 2014-02-28 10:57:58.578 Using stored password.
. 2014-02-28 10:57:58.578 Sent password
. 2014-02-28 10:57:58.594 Access granted
. 2014-02-28 10:57:58.594 Opening session as main channel
. 2014-02-28 10:57:58.609 Opened main channel
. 2014-02-28 10:57:58.719 Started a shell/command
. 2014-02-28 10:57:58.719 --------------------------------------------------------------------------
. 2014-02-28 10:57:58.719 Using SFTP protocol.
. 2014-02-28 10:57:58.719 Doing startup conversation with host.
> 2014-02-28 10:57:58.719 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2014-02-28 10:57:58.734 Type: SSH_FXP_VERSION, Size: 5, Number: -1
. 2014-02-28 10:57:58.734 SFTP version 3 negotiated.
. 2014-02-28 10:57:58.734 We believe the server has signed timestamps bug
. 2014-02-28 10:57:58.734 We will use UTF-8 strings when appropriate
. 2014-02-28 10:57:58.734 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2014-02-28 10:57:58.734 Getting current directory name.
. 2014-02-28 10:57:58.734 Getting real path for '.'
> 2014-02-28 10:57:58.734 Type: SSH_FXP_REALPATH, Size: 10, Number: 16. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 WinSCP Version 5.5.1 (Build 3970) (OS 6.1.7601 Service Pack 1 - Windows Server 2008 R2 Standard)
. 2014-02-28 10:57:57.689 Configuration: C:\Program Files (x86)\WinSCP\WinSCP.ini
. 2014-02-28 10:57:57.689 Local account: <windows-admin>
. 2014-02-28 10:57:57.689 Working directory: C:\RO\OrderXML
. 2014-02-28 10:57:57.689 Process ID: 7524
. 2014-02-28 10:57:57.689 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" /console=551 /consoleinstance=_4504_607 "/log=C:\RO\OrderXML\!T!S.log" "/command" "option batch abort" "option confirm off" "open sftp://<unm>:<pwd>@<ftp-server>" "put C:\LocalDirectory\*.xml /remotedirectory/" "exit"
. 2014-02-28 10:57:57.689 Time zone: Current: GMT-6, Standard: GMT-6, DST: GMT-5, DST Start: 3/9/2014, DST End: 11/2/2014
. 2014-02-28 10:57:57.689 Login time: Friday, February 28, 2014 10:57:57 AM
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 Script: Retrospectivelly logging previous script records:
> 2014-02-28 10:57:57.689 Script: option batch abort
< 2014-02-28 10:57:57.689 Script: batch abort
> 2014-02-28 10:57:57.689 Script: option confirm off
< 2014-02-28 10:57:57.689 Script: confirm off
> 2014-02-28 10:57:57.689 Script: open sftp://<unm>***@<ftp-server>
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 Session name: <unm>@<ftp-server> (Ad-Hoc site)
. 2014-02-28 10:57:57.689 Host name: <ftp-server> (Port: 22)
. 2014-02-28 10:57:57.689 User name: <unm> (Password: Yes, Key file: No)
. 2014-02-28 10:57:57.689 Tunnel: No
. 2014-02-28 10:57:57.689 Transfer Protocol: SFTP
. 2014-02-28 10:57:57.689 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2014-02-28 10:57:57.689 Proxy: none
. 2014-02-28 10:57:57.689 Send buffer: 262144
. 2014-02-28 10:57:57.689 SSH protocol version: 2; Compression: No
. 2014-02-28 10:57:57.689 Bypass authentication: No
. 2014-02-28 10:57:57.689 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2014-02-28 10:57:57.689 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2014-02-28 10:57:57.689 SSH Bugs: A,A,A,A,A,A,A,A,A,A
. 2014-02-28 10:57:57.689 Simple channel: Yes
. 2014-02-28 10:57:57.689 Return code variable: Autodetect; Lookup user groups: A
. 2014-02-28 10:57:57.689 Shell: default
. 2014-02-28 10:57:57.689 EOL: 0, UTF: 2
. 2014-02-28 10:57:57.689 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2014-02-28 10:57:57.689 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2014-02-28 10:57:57.689 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2014-02-28 10:57:57.689 Cache directory changes: Yes, Permanent: Yes
. 2014-02-28 10:57:57.689 DST mode: 1; Timezone offset: 0h 0m
. 2014-02-28 10:57:57.689 --------------------------------------------------------------------------
. 2014-02-28 10:57:57.689 Looking up host "<ftp-server>"
. 2014-02-28 10:57:57.689 Connecting to <ftp-server> port 22
. 2014-02-28 10:57:57.736 Server version: SSH-2.0-OpenSSH_4.3
. 2014-02-28 10:57:57.736 Using SSH protocol version 2
. 2014-02-28 10:57:57.736 We claim version: SSH-2.0-WinSCP_release_5.5.1
. 2014-02-28 10:57:57.751 Doing Diffie-Hellman group exchange
. 2014-02-28 10:57:57.829 Doing Diffie-Hellman key exchange with hash SHA-1
. 2014-02-28 10:57:58.485 Verifying host key rsa2 ****
. 2014-02-28 10:57:58.485 Host key matches cached key
. 2014-02-28 10:57:58.485 Host key fingerprint is:
. 2014-02-28 10:57:58.485 ssh-rsa 2048 ****
. 2014-02-28 10:57:58.485 Initialised AES-256 SDCTR client->server encryption
. 2014-02-28 10:57:58.485 Initialised HMAC-SHA1 client->server MAC algorithm
. 2014-02-28 10:57:58.485 Initialised AES-256 SDCTR server->client encryption
. 2014-02-28 10:57:58.485 Initialised HMAC-SHA1 server->client MAC algorithm
! 2014-02-28 10:57:58.563 Using username "<unm>".
. 2014-02-28 10:57:58.578 Prompt (7, SSH password, , &Password: )
. 2014-02-28 10:57:58.578 Using stored password.
. 2014-02-28 10:57:58.578 Sent password
. 2014-02-28 10:57:58.594 Access granted
. 2014-02-28 10:57:58.594 Opening session as main channel
. 2014-02-28 10:57:58.609 Opened main channel
. 2014-02-28 10:57:58.719 Started a shell/command
. 2014-02-28 10:57:58.719 --------------------------------------------------------------------------
. 2014-02-28 10:57:58.719 Using SFTP protocol.
. 2014-02-28 10:57:58.719 Doing startup conversation with host.
> 2014-02-28 10:57:58.719 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2014-02-28 10:57:58.734 Type: SSH_FXP_VERSION, Size: 5, Number: -1
. 2014-02-28 10:57:58.734 SFTP version 3 negotiated.
. 2014-02-28 10:57:58.734 We believe the server has signed timestamps bug
. 2014-02-28 10:57:58.734 We will use UTF-8 strings when appropriate
. 2014-02-28 10:57:58.734 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2014-02-28 10:57:58.734 Getting current directory name.
. 2014-02-28 10:57:58.734 Getting real path for '.'
> 2014-02-28 10:57:58.734 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2014-02-28 10:57:58.750 Type: SSH_FXP_NAME, Size: 71, Number: 16
. 2014-02-28 10:57:58.750 Real path is '/remotedirectory'
. 2014-02-28 10:57:58.750 Startup conversation with host finished.
< 2014-02-28 10:57:58.750 Script: Active session: [1] <unm>@<ftp-server>
> 2014-02-28 10:57:58.750 Script: put C:\LocalDirectory\*.xml /remotedirectory/
. 2014-02-28 10:57:58.750 Copying 1 files/directories to remote directory "/remotedirectory/"
. 2014-02-28 10:57:58.750 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
. 2014-02-28 10:57:58.750 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM:
. 2014-02-28 10:57:58.750 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2014-02-28 10:57:58.765 File: 'C:\LocalDirectory\FC00469_0001_0001.xml' [2014-02-27T23:46:50.250Z] [6200]
. 2014-02-28 10:57:58.765 Copying "C:\LocalDirectory\FC00469_0001_0001.xml" to remote directory started.
. 2014-02-28 10:57:58.765 Binary transfer mode selected.
. 2014-02-28 10:57:58.765 Opening remote file.
> 2014-02-28 10:57:58.765 Type: SSH_FXP_OPEN, Size: 69, Number: 259
< 2014-02-28 10:57:58.781 Type: SSH_FXP_HANDLE, Size: 13, Number: 259
> 2014-02-28 10:57:58.781 Type: SSH_FXP_WRITE, Size: 4121, Number: 774
. 2014-02-28 10:57:58.781 1 skipped SSH_FXP_WRITE, SSH_FXP_READ, SSH_FXP_DATA and SSH_FXP_STATUS packets.
> 2014-02-28 10:57:58.781 Type: SSH_FXP_CLOSE, Size: 13, Number: 1284
> 2014-02-28 10:57:58.781 Type: SSH_FXP_SETSTAT, Size: 65, Number: 521
< 2014-02-28 10:57:58.812 Type: SSH_FXP_STATUS, Size: 24, Number: 774
< 2014-02-28 10:57:59.093 Type: SSH_FXP_STATUS, Size: 24, Number: 1030
< 2014-02-28 10:57:59.093 Type: SSH_FXP_STATUS, Size: 24, Number: 1284
< 2014-02-28 10:57:59.093 Status code: 0
. 2014-02-28 10:57:59.093 Preserving timestamp [2014-02-27T23:46:50.000Z]
< 2014-02-28 10:57:59.093 Type: SSH_FXP_STATUS, Size: 24, Number: 521
< 2014-02-28 10:57:59.093 Status code: 0
> 2014-02-28 10:57:59.093 Script: exit
. 2014-02-28 10:57:59.093 Script: Exit code: 0
. 2014-02-28 10:57:59.093 Closing connection.
. 2014-02-28 10:57:59.093 Sending special code: 12
. 2014-02-28 10:57:59.093 Sent EOF message
< 2014-02-28 10:57:58.750 Type: SSH_FXP_NAME, Size: 71, Number: 16
. 2014-02-28 10:57:58.750 Real path is '/remotedirectory'
. 2014-02-28 10:57:58.750 Startup conversation with host finished.
< 2014-02-28 10:57:58.750 Script: Active session: [1] <unm>@<ftp-server>
> 2014-02-28 10:57:58.750 Script: put C:\LocalDirectory\*.xml /remotedirectory/
. 2014-02-28 10:57:58.750 Copying 1 files/directories to remote directory "/remotedirectory/"
. 2014-02-28 10:57:58.750 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
. 2014-02-28 10:57:58.750 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM:
. 2014-02-28 10:57:58.750 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2014-02-28 10:57:58.765 File: 'C:\LocalDirectory\FC00469_0001_0001.xml' [2014-02-27T23:46:50.250Z] [6200]
. 2014-02-28 10:57:58.765 Copying "C:\LocalDirectory\FC00469_0001_0001.xml" to remote directory started.
. 2014-02-28 10:57:58.765 Binary transfer mode selected.
. 2014-02-28 10:57:58.765 Opening remote file.
> 2014-02-28 10:57:58.765 Type: SSH_FXP_OPEN, Size: 69, Number: 259
< 2014-02-28 10:57:58.781 Type: SSH_FXP_HANDLE, Size: 13, Number: 259
> 2014-02-28 10:57:58.781 Type: SSH_FXP_WRITE, Size: 4121, Number: 774
. 2014-02-28 10:57:58.781 1 skipped SSH_FXP_WRITE, SSH_FXP_READ, SSH_FXP_DATA and SSH_FXP_STATUS packets.
> 2014-02-28 10:57:58.781 Type: SSH_FXP_CLOSE, Size: 13, Number: 1284
> 2014-02-28 10:57:58.781 Type: SSH_FXP_SETSTAT, Size: 65, Number: 521
< 2014-02-28 10:57:58.812 Type: SSH_FXP_STATUS, Size: 24, Number: 774
< 2014-02-28 10:57:59.093 Type: SSH_FXP_STATUS, Size: 24, Number: 1030
< 2014-02-28 10:57:59.093 Type: SSH_FXP_STATUS, Size: 24, Number: 1284
< 2014-02-28 10:57:59.093 Status code: 0
. 2014-02-28 10:57:59.093 Preserving timestamp [2014-02-27T23:46:50.000Z]
< 2014-02-28 10:57:59.093 Type: SSH_FXP_STATUS, Size: 24, Number: 521
< 2014-02-28 10:57:59.093 Status code: 0
> 2014-02-28 10:57:59.093 Script: exit
. 2014-02-28 10:57:59.093 Script: Exit code: 0
. 2014-02-28 10:57:59.093 Closing connection.
. 2014-02-28 10:57:59.093 Sending special code: 12
. 2014-02-28 10:57:59.093 Sent EOF message