Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

mferrero@ender.es

Ok. Thanks.

I Try this solucion
martin

Re: Status code always return 1

This is not really WinSCP question.
Your batch file syntax is wrong. %ERRORLEVEL% does not work within for loop.

This does what you want


SETLOCAL EnableDelayedExpansion
For /F "tokens=*" %%a in ('Dir *.pdf /B /A-D') do (
"E:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script=Subir.bat /parameter "%%a" /log=log.txt
echo !ERRORLEVEL!
"E:\Program Files (x86)\WinSCP\WinSCP.com" /command "open sftp://user:***@ftpserver -hostkey=*" "option failonnomatch on" "cd <directory FTP>" "ls %%a" "exit"
echo !ERRORLEVEL!

)
mferrero@ender.es

Status code always return 1

Hello,

First, sorry for my English

I'm new from WinSPC

I try to make an script to upload file to ftp. The files upload correctly, but when i try to get status code, always return 1.
I try several method, but always return 1

I have 2 scripts

************ Copia.bat ******

@echo off
@echo recorriendo ficheros

For /F "tokens=*" %%a in ('Dir *.pdf /B /A-D') do (
"E:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script=Subir.bat /parameter "%%a" /log=log.txt
echo %ERRORLEVEL%
"E:\Program Files (x86)\WinSCP\WinSCP.com" /command "open sftp://user:***@ftpserver -hostkey=*" "option failonnomatch on" "cd <directory FTP>" "ls %%a" "exit"
echo %ERRORLEVEL%

)

***** Subir.bat ****
option echo on
option batch on
option confirm off
option transfer binary

open sftp://user:****@ftpserver -hostkey=*
cd <directory FTP>
put -nopermissions -nopreservetime "%1%"
close
exit

*********

****** Log.txt **********
. 2018-05-22 20:43:59.112 --------------------------------------------------------------------------
. 2018-05-22 20:43:59.113 WinSCP Versión 5.13.2 (Compilación 8455) (OS 10.0.17134 - Windows 10 Home)
. 2018-05-22 20:43:59.113 Configuration: nul
. 2018-05-22 20:43:59.113 Log level: Normal
. 2018-05-22 20:43:59.113 Local account: <My account>
. 2018-05-22 20:43:59.113 Working directory: <local directory>
. 2018-05-22 20:43:59.113 Process ID: 4128
. 2018-05-22 20:43:59.118 Command-line: "E:\Program Files (x86)\WinSCP\WinSCP.exe" /console=5.13.2 /consoleinstance=_10800_17 "/ini=nul" "/script=Subir.bat" "/parameter" "0605065_Condiciones.pdf" "/log=log.txt"
. 2018-05-22 20:43:59.118 Time zone: Current: GMT+2, Standard: GMT+1 (Hora estándar romance), DST: GMT+2 (Hora de verano romance), DST Start: 25/03/2018, DST End: 28/10/2018
. 2018-05-22 20:43:59.119 Login time: martes, 22 de mayo de 2018 20:43:59
. 2018-05-22 20:43:59.119 --------------------------------------------------------------------------
. 2018-05-22 20:43:59.119 Script: Retrospectively logging previous script records:
> 2018-05-22 20:43:59.119 Script: option echo on
< 2018-05-22 20:43:59.119 Script: echo on
> 2018-05-22 20:43:59.119 Script: option batch on
< 2018-05-22 20:43:59.119 Script: option batch on
< 2018-05-22 20:43:59.119 Script: batch on
> 2018-05-22 20:43:59.119 Script: option confirm off
< 2018-05-22 20:43:59.119 Script: option confirm off
< 2018-05-22 20:43:59.119 Script: confirm off
> 2018-05-22 20:43:59.119 Script: option transfer binary
< 2018-05-22 20:43:59.119 Script: option transfer binary
< 2018-05-22 20:43:59.119 Script: transfer binary
> 2018-05-22 20:43:59.119 Script: open sftp://user:****@ftpserver -hostkey=*
< 2018-05-22 20:43:59.119 Script: open sftp://user:****@ftpserver -hostkey=*
. 2018-05-22 20:43:59.119 --------------------------------------------------------------------------
. 2018-05-22 20:43:59.119 Session name: user@ftpserver (Ad-Hoc site)
. 2018-05-22 20:43:59.119 Host name: ftpserver (Port: 22)
. 2018-05-22 20:43:59.119 User name: user (Password: Yes, Key file: No, Passphrase: No)
. 2018-05-22 20:43:59.119 Tunnel: No
. 2018-05-22 20:43:59.119 Transfer Protocol: SFTP
. 2018-05-22 20:43:59.119 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2018-05-22 20:43:59.119 Disable Nagle: No
. 2018-05-22 20:43:59.119 Proxy: None
. 2018-05-22 20:43:59.119 Send buffer: 262144
. 2018-05-22 20:43:59.119 SSH protocol version: 2; Compression: No
. 2018-05-22 20:43:59.120 Bypass authentication: No
. 2018-05-22 20:43:59.120 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2018-05-22 20:43:59.120 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2018-05-22 20:43:59.120 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2018-05-22 20:43:59.120 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2018-05-22 20:43:59.120 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2018-05-22 20:43:59.120 Simple channel: Yes
. 2018-05-22 20:43:59.120 Return code variable: Autodetect; Lookup user groups: Auto
. 2018-05-22 20:43:59.120 Shell: default
. 2018-05-22 20:43:59.120 EOL: LF, UTF: Auto
. 2018-05-22 20:43:59.120 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2018-05-22 20:43:59.120 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2018-05-22 20:43:59.120 SFTP Bugs: Auto,Auto
. 2018-05-22 20:43:59.120 SFTP Server: default
. 2018-05-22 20:43:59.120 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2018-05-22 20:43:59.120 Cache directory changes: Yes, Permanent: Yes
. 2018-05-22 20:43:59.120 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2018-05-22 20:43:59.120 DST mode: Unix
. 2018-05-22 20:43:59.120 --------------------------------------------------------------------------
. 2018-05-22 20:43:59.121 Looking up host "ftpserver" for SSH connection
. 2018-05-22 20:43:59.145 Connecting to xx.xx.xxx.xxx port 22
. 2018-05-22 20:43:59.194 We claim version: SSH-2.0-WinSCP_release_5.13.2
. 2018-05-22 20:43:59.251 Server version: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
. 2018-05-22 20:43:59.252 Using SSH protocol version 2
. 2018-05-22 20:43:59.302 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2018-05-22 20:44:00.070 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2018-05-22 20:44:00.072 Host key fingerprint is:
. 2018-05-22 20:44:00.072 ssh-ed25519 256 a7:48:72:b0:3d:13:1b:40:4e:5f:1f:a2:06:8b:fe:60 q44hC1uXiA8LmPVPPrT26jkr9UycqoN3v6ATyP3u39s=
* 2018-05-22 20:44:00.074 ¡ATENCIÓN! ¡Según la configuración, se prescinde de la seguridad y se admite cualquier clave de equipo!
. 2018-05-22 20:44:00.075 Initialised AES-256 SDCTR client->server encryption
. 2018-05-22 20:44:00.075 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2018-05-22 20:44:00.075 Initialised AES-256 SDCTR server->client encryption
. 2018-05-22 20:44:00.075 Initialised HMAC-SHA-256 server->client MAC algorithm
! 2018-05-22 20:44:00.213 Using username "user".
. 2018-05-22 20:44:00.263 Server offered these authentication methods: publickey,password
. 2018-05-22 20:44:00.263 Prompt (password, "SSH password", <no instructions>, "&Contraseña:")
. 2018-05-22 20:44:00.264 Using stored password.
. 2018-05-22 20:44:00.264 Sent password
. 2018-05-22 20:44:00.327 Access granted
. 2018-05-22 20:44:00.327 Opening session as main channel
. 2018-05-22 20:44:00.465 Opened main channel
. 2018-05-22 20:44:00.606 Started a shell/command
. 2018-05-22 20:44:00.606 --------------------------------------------------------------------------
. 2018-05-22 20:44:00.606 Using SFTP protocol.
. 2018-05-22 20:44:00.607 Doing startup conversation with host.
> 2018-05-22 20:44:00.608 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2018-05-22 20:44:00.657 Type: SSH_FXP_VERSION, Size: 150, Number: -1
. 2018-05-22 20:44:00.658 SFTP version 3 negotiated.
. 2018-05-22 20:44:00.658 Unknown server extension posix-rename@openssh.com="1"
. 2018-05-22 20:44:00.658 Supports statvfs@openssh.com extension version "2"
. 2018-05-22 20:44:00.658 Unknown server extension fstatvfs@openssh.com="2"
. 2018-05-22 20:44:00.658 Supports hardlink@openssh.com extension version "1"
. 2018-05-22 20:44:00.658 Unknown server extension fsync@openssh.com="1"
. 2018-05-22 20:44:00.658 We believe the server has signed timestamps bug
. 2018-05-22 20:44:00.658 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory
. 2018-05-22 20:44:00.658 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2018-05-22 20:44:00.658 Getting current directory name.
. 2018-05-22 20:44:00.658 Getting real path for '.'
> 2018-05-22 20:44:00.658 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2018-05-22 20:44:00.707 Type: SSH_FXP_NAME, Size: 31, Number: 16
. 2018-05-22 20:44:00.707 Real path is '/user'
. 2018-05-22 20:44:00.707 Startup conversation with host finished.
< 2018-05-22 20:44:00.708 Script: Sesión activa: [1] user@ftpserver
> 2018-05-22 20:44:00.710 Script: cd <directory FTP>
< 2018-05-22 20:44:00.710 Script: cd <directory FTP>
. 2018-05-22 20:44:00.710 Changing directory to "<directory FTP>".
. 2018-05-22 20:44:00.710 Getting real path for '<directory FTP>'
> 2018-05-22 20:44:00.710 Type: SSH_FXP_REALPATH, Size: 84, Number: 272
< 2018-05-22 20:44:00.760 Type: SSH_FXP_NAME, Size: 171, Number: 272
. 2018-05-22 20:44:00.760 Real path is '<directory FTP>'
. 2018-05-22 20:44:00.760 Trying to open directory "<directory FTP>".
> 2018-05-22 20:44:00.760 Type: SSH_FXP_LSTAT, Size: 84, Number: 519
< 2018-05-22 20:44:00.810 Type: SSH_FXP_ATTRS, Size: 37, Number: 519
. 2018-05-22 20:44:00.810 Getting current directory name.
< 2018-05-22 20:44:00.810 Script: <directory FTP>
> 2018-05-22 20:44:00.812 Script: put -nopermissions -nopreservetime "0605065_Condiciones.pdf"
< 2018-05-22 20:44:00.812 Script: put -nopermissions -nopreservetime "0605065_Condiciones.pdf"
. 2018-05-22 20:44:00.813 Copying 1 files/directories to remote directory "<directory FTP>" - total size: 862.514
. 2018-05-22 20:44:00.813 PrTime: No; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask:
. 2018-05-22 20:44:00.813 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
. 2018-05-22 20:44:00.813 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
. 2018-05-22 20:44:00.813 Getting real path for '<directory FTP>'
> 2018-05-22 20:44:00.813 Type: SSH_FXP_REALPATH, Size: 84, Number: 784
< 2018-05-22 20:44:00.863 Type: SSH_FXP_NAME, Size: 171, Number: 784
. 2018-05-22 20:44:00.863 Real path is '<directory FTP>'
. 2018-05-22 20:44:00.863 File: '0605065_Condiciones.pdf' [2018-03-14T10:08:03.657Z] [862514]
. 2018-05-22 20:44:00.864 Copying "0605065_Condiciones.pdf" to remote directory started.
. 2018-05-22 20:44:00.864 Binary transfer mode selected.
. 2018-05-22 20:44:00.864 Checking existence of file.
> 2018-05-22 20:44:00.864 Type: SSH_FXP_LSTAT, Size: 108, Number: 1031
< 2018-05-22 20:44:00.913 Type: SSH_FXP_STATUS, Size: 29, Number: 1031
< 2018-05-22 20:44:00.913 Status code: 2
. 2018-05-22 20:44:00.913 Checking existence of partially transferred file.
> 2018-05-22 20:44:00.914 Type: SSH_FXP_LSTAT, Size: 117, Number: 1287
< 2018-05-22 20:44:00.963 Type: SSH_FXP_STATUS, Size: 29, Number: 1287
< 2018-05-22 20:44:00.963 Status code: 2
. 2018-05-22 20:44:00.963 Opening remote file.
> 2018-05-22 20:44:00.963 Type: SSH_FXP_OPEN, Size: 133, Number: 1539
< 2018-05-22 20:44:01.012 Type: SSH_FXP_HANDLE, Size: 13, Number: 1539
> 2018-05-22 20:44:01.013 Type: SSH_FXP_WRITE, Size: 32764, Number: 2054
. 2018-05-22 20:44:01.214 Increasing send buffer from 262144 to 524288
. 2018-05-22 20:44:01.275 39 skipped SSH_FXP_WRITE, SSH_FXP_READ, SSH_FXP_DATA and SSH_FXP_STATUS packets.
> 2018-05-22 20:44:01.275 Type: SSH_FXP_CLOSE, Size: 13, Number: 8964
< 2018-05-22 20:44:01.308 Type: SSH_FXP_STATUS, Size: 24, Number: 5382
< 2018-05-22 20:44:01.308 Status code: 0
< 2018-05-22 20:44:01.358 Type: SSH_FXP_STATUS, Size: 24, Number: 5638
< 2018-05-22 20:44:01.358 Status code: 0
< 2018-05-22 20:44:01.359 Type: SSH_FXP_STATUS, Size: 24, Number: 5894
< 2018-05-22 20:44:01.359 Status code: 0
< 2018-05-22 20:44:01.359 Type: SSH_FXP_STATUS, Size: 24, Number: 6150
< 2018-05-22 20:44:01.359 Status code: 0
< 2018-05-22 20:44:01.361 Type: SSH_FXP_STATUS, Size: 24, Number: 6406
< 2018-05-22 20:44:01.361 Status code: 0
< 2018-05-22 20:44:01.361 Type: SSH_FXP_STATUS, Size: 24, Number: 6662
< 2018-05-22 20:44:01.361 Status code: 0
< 2018-05-22 20:44:01.362 Type: SSH_FXP_STATUS, Size: 24, Number: 6918
< 2018-05-22 20:44:01.362 Status code: 0
< 2018-05-22 20:44:01.362 Type: SSH_FXP_STATUS, Size: 24, Number: 7174
< 2018-05-22 20:44:01.362 Status code: 0
< 2018-05-22 20:44:01.362 Type: SSH_FXP_STATUS, Size: 24, Number: 7430
< 2018-05-22 20:44:01.362 Status code: 0
< 2018-05-22 20:44:01.363 Type: SSH_FXP_STATUS, Size: 24, Number: 7686
< 2018-05-22 20:44:01.363 Status code: 0
< 2018-05-22 20:44:01.406 Type: SSH_FXP_STATUS, Size: 24, Number: 7942
< 2018-05-22 20:44:01.406 Status code: 0
< 2018-05-22 20:44:01.407 Type: SSH_FXP_STATUS, Size: 24, Number: 8198
< 2018-05-22 20:44:01.407 Status code: 0
< 2018-05-22 20:44:01.407 Type: SSH_FXP_STATUS, Size: 24, Number: 8454
< 2018-05-22 20:44:01.407 Status code: 0
< 2018-05-22 20:44:01.407 Type: SSH_FXP_STATUS, Size: 24, Number: 8710
< 2018-05-22 20:44:01.407 Status code: 0
< 2018-05-22 20:44:01.407 Type: SSH_FXP_STATUS, Size: 24, Number: 8964
< 2018-05-22 20:44:01.407 Status code: 0
> 2018-05-22 20:44:01.407 Type: SSH_FXP_RENAME, Size: 220, Number: 9234
< 2018-05-22 20:44:01.457 Type: SSH_FXP_STATUS, Size: 24, Number: 9234
< 2018-05-22 20:44:01.457 Status code: 0
. 2018-05-22 20:44:01.457 Transfer done: '0605065_Condiciones.pdf' => '<directory FTP>/0605065_Condiciones.pdf' [862514]
. 2018-05-22 20:44:01.458 Copying finished: Transferred: 862.514, Elapsed: 0:00:00, CPS: 1.894.463/s
> 2018-05-22 20:44:01.458 Script: close
< 2018-05-22 20:44:01.458 Script: close
. 2018-05-22 20:44:01.459 Closing connection.
. 2018-05-22 20:44:01.459 Sending special code: 12
. 2018-05-22 20:44:01.459 Sent EOF message
******

Somebody can help my