v.5.1.4 ERRORLEVEL is equal to 0 after authentication failed

Advertisement

kosmo
Joined:
Posts:
2

v.5.1.4 ERRORLEVEL is equal to 0 after authentication failed

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
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
option batch abort
option confirm off

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

shows me
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
< 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)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,468
Location:
Prague, Czechia

Re: v.5.1.4 ERRORLEVEL is equal to 0 after authentication failed

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.

Reply with quote

kosmo
Joined:
Posts:
2

Cleared out: my mistake

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
@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:
@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...

Reply with quote

Advertisement

You can post new topics in this forum