Topic "v.5.1.4 ERRORLEVEL is equal to 0 after authentication failed"

Author Message
kosmo
[View user's profile]

Joined: 2013-03-04
Posts: 2
Hi!
I'm running portable version of 5.1.4 on Win 2000 SP4 x86 machine and getting %ERRORLEVEL% equal to 0 if authentication for protocol FTP fails
I'm analyzing this variable and depending on its value deleting files prepared for transfer.

batch file
Code:

set ftp_user=u
set ftp_pass=p
set ftp_host=ftp.example.com
set source_mask=C:\Temp\*.txt

winscp.com /script=script.txt /log=winscp.log
echo Error: %ERRORLEVEL%


script file
Code:
option batch abort
option confirm off

open ftp://%ftp_user%:%ftp_pass%@%ftp_host%
option transfer binary
put "%source_mask%"
close
exit


shows me
Code:

batch           abort     
confirm         off       
Connecting to ftp.example.com ...
Connected with ftp.example.com. Waiting for welcome message...
Access denied.
Authentication failed.

Error: 0


log's tail
Code:

< 2013-03-04 16:57:09.188 331 Password required for u
> 2013-03-04 16:57:09.188 PASS *
< 2013-03-04 16:57:09.204 530 Login incorrect
. 2013-03-04 16:57:09.204 Connection failed.
. 2013-03-04 16:57:09.204 Password prompt (last login attempt failed)
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24552
Location: Prague, Czechia
Please attach a full log file showing the problem.

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.
kosmo
[View user's profile]

Joined: 2013-03-04
Posts: 2
Hi Martin,

sorry, found out the reason in full version of script!
Short answer: need to use delayed expansion, if you are in statements group
Long answer: after examining my original script
Code:
@echo off

set ftp_host=localhost
set ftp_user=u
set ftp_pass=p

set source_folder=C:\Temp
set source_pattern=*.txt

set winscp_root=winscp

set source_mask=%source_folder%\%source_pattern%


setlocal

if exist "%source_mask%" (

   "%winscp_root%\winscp.com" /script=PutFiles.ftp > "%TEMP%\winscp.out"

   if %ERRORLEVEL% EQU 0 (
      
      echo Success
      
   ) else (
      echo Problem while copying files
      
   )
   
) else (
   echo No files to upload
)

endlocal


I've found out that all assignments in if exist "%source_mask%" ( ... ) block are not actual within the same block.
So I changed my piece of code in the following way:
Code:

@echo off

set ftp_host=localhost
set ftp_user=u
set ftp_pass=p

set source_folder=C:\Temp
set source_pattern=*.txt

set winscp_root=winscp

set source_mask=%source_folder%\%source_pattern%


setlocal enabledelayedexpansion

if exist "%source_mask%" (

   "%winscp_root%\winscp.com" /script=PutFiles.ftp > "%TEMP%\winscp.out"

   if !ERRORLEVEL! EQU 0 (
      
      echo Success
      
   ) else (
      echo Problem while copying files
      
   )
   
) else (
   echo No files to upload
)

endlocal

and it worked! Sorry for disturbing...
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