FTP file retrieval problem: error 503 use Auth first.

xda_7822 Posted messages 7 Status Membre -  
brupala Posted messages 111942 Registration date   Status Membre Last intervention   -

Hello,

I created a very simple .bat to upload a file every day from a remote server that I access via FTP.

If I use Filezilla, I can connect, but my batch returns the error "503 use Auth first" and I can't get around this problem.

The error occurs after the instruction "echo user USER_TOTO MDP_TOTO"

If someone can save me !!!!!

Below is my batch

echo off

set path=C:\toto

(

    echo open int-clt.toto.fr 21000

    echo user USER_TOTO MDP_TOTO

    echo prompt

    echo binary

    echo get /SOC-TIERS.CSV

    echo disconnect

    echo bye

) >> %path%\log.ftp

cd C:\WINDOWS\system32

ftp -s:C:\toto\log.ftp -n

pause >nul

5 réponses

contrariness Posted messages 338 Registration date   Status Membre Last intervention   6 240
 

I'm not a batch specialist, but the error indicates that you're trying to perform an action before you have authenticated yourself...
Wouldn't there be 2 lines to swap in your batch?

0
brucine Posted messages 24389 Registration date   Status Membre Last intervention   4 099
 

Hello,

No, since the ftp command reads the configuration file log.ftp before being executed and the authentication occurs just after the connection.

This configuration file does not necessarily have to be in .ftp format (.txt is enough) and we do not see the point of recreating it on the fly with each execution.

If we do not want the persistence of identifiers, we will need to delete the Batch, back to square one, or integrate into the Batch the deletion of the .txt file from the disk after use.

Back to our business, it seems to me that if we want the username and password to be on the same line, we must, like the others, use the -n switch before the filename:

ftp -n -s:C:\toto\log.ftp

But since we do not write endlessly and go through a configuration file, nothing prevents us, this time without the -n switch, instead of:

echo user username password

two successive lines:

echo username
echo password

The PATH command is also debatable (I just need to qualify the copy path of the script), and the one that follows is useless since C:\Windows\System32 is part of the default PATH and ftp.exe is located there.

0
xda_7822 Posted messages 7 Status Membre > brucine Posted messages 24389 Registration date   Status Membre Last intervention  
 

Hello brucine, thank you for taking an interest in my issue. As for deleting the log.ftp, I agree that the primary goal is to download a file; the final purpose of the script is for later.

I also tested with a batch containing the line

ftp -s:toto.ftp and also ftp -s:toto.ftp -n

then the script:

open int-clt.toto.fr 21000
AUTH TLS
user ID_TOTO MDP_TOTO
prompt
get /SOC-TIERS.CSV
quit

But I get the same error.

I also note that you talk about doing 2 identification lines

echo username
echo password

I had already looked into that, but the line

echo password MDP_TOTO returns an error "invalid command".

0
brucine Posted messages 24389 Registration date   Status Membre Last intervention   4 099 > xda_7822 Posted messages 7 Status Membre
 

I have no errors in the Log file after faithfully copying your script except of course for the customized folder and the ftp command itself, although it is a global echo, but to each his own, I prefer to redirect each line:

echo open int-clt.toto.fr 21000>>log.txt

echo user USER_TOTO MDP_TOTO>>log.txt

There is no reason for the echo command not to be valid, it copies what is requested by the mile except for unescaped special characters.

But it’s not echo password MDP_TOTO>>log.txt but
echo MDP_TOTO>>log.txt: the ftp sequence knows that, in order, it expects the username and password.

0
xda_7822 Posted messages 7 Status Membre
 

thank you for your help but no that's not it I've already tried

0
contrariness Posted messages 338 Registration date   Status Membre Last intervention   6 240
 

And Filezilla, doesn't it have an error log?

0
xda_7822 Posted messages 7 Status Membre
 

No, when I connect with Filezilla, everything goes well. Except of course my goal is not to use Filezilla but to create a .bat to put it in a scheduled task later and automate the retrieval of the file in question.

0
brucine Posted messages 24389 Registration date   Status Membre Last intervention   4 099
 

Hello,

If I remember correctly (it's been a while since I last worked on this), FileZilla cannot "script" except for the fzcli command of FileZilla Pro, which is paid.

This would explain the error observed via FileZilla (but not the one via the ftp command, which uses the default Windows ftp client).

0
brupala Posted messages 111942 Registration date   Status Membre Last intervention   14 421
 

Hello,

the ftp command does not exist

user toto pwd

it's user toto that's it and you have to wait for the prompt for the password

for example by a pause, then the password.

I don't think you can do ftp with such a batch, you need to wait for the prompt and respond afterwards.

I used to do things like that but with Teraterm scripts which are much more powerful.

On top of that, you NEVER put a password in plain text in a script.


And there you go, voilà ....

But misery, how annoying the line spacing is!!

0
brucine Posted messages 24389 Registration date   Status Membre Last intervention   4 099
 

Hello,

Of course, the single line meeting is used after the switch
ftp -n that resets the password, see for example here in 19.
https://stackoverflow.com/questions/16158138/how-to-ftp-with-a-batch-file

I don't like the syntax and I prefer to use two separate entries, but that doesn't mean it doesn't exist.

If we enter the password on the fly and there are other potential users of the PC, we of course need to either destroy the script itself after use or destroy the parameter file, see for example here but that's another question:
https://www.robvanderwoude.com/ftp.php

0
brupala Posted messages 111942 Registration date   Status Membre Last intervention   14 421 > brucine Posted messages 24389 Registration date   Status Membre Last intervention  
 

On the other hand, there's a simpler way:

the commands curl or wget.

Curl is included in Windows: https://www.ionos.fr/digitalguide/serveur/outils/debuter-dans-curl-sous-windows/ and wget can be easily installed there.

Both accept the URL format:

add the output folder with -o in curl and -O in wget and it should work better than ftp.

curl also allows upload.

0
xda_7822 Posted messages 7 Status Membre > brupala Posted messages 111942 Registration date   Status Membre Last intervention  
 

Thank you brupala,

I tested curl (which I wasn't familiar with), it seems easy but ultimately I end up with the same result: error curl: (67) Access denied: 503

0
brupala Posted messages 111942 Registration date   Status Membre Last intervention   14 421 > xda_7822 Posted messages 7 Status Membre
 

What command line do you use?

0
xda_7822 Posted messages 7 Status Membre > brupala Posted messages 111942 Registration date   Status Membre Last intervention  
 

curl -k ftp://int-clt.TOTO.fr:21000 --user USERTOTO:MDP_TOTO

I haven't even added a line to retrieve the file. I'm only at the connection stage.

0
xda_7822 Posted messages 7 Status Membre
 

Thank you all for your help.

The problem is resolved; the FTP command did not handle TLS formats (I believe I understood that it was due to the old version of Windows Server from which the command was launched).

I ultimately installed WinSCP and wrote this very simple batch that works very well

1 the .bat

del "c:\destination_directory\*.CSV" /Q

del "c:\toto\log.txt\*.CSV" /Q

"c:\program files (x86)\winscp\winscp.exe" /log="c:\toto\log.txt" /ini=nul /script="c:\toto\script.txt"

2 the script command file script.TXT

open ftpes://username:password@server_name:port_number/

get /*.csv "c:\destination_directory\*.*"

exit

0
brupala Posted messages 111942 Registration date   Status Membre Last intervention   14 421
 

Yes,

winscp, I didn't know it supported ftps, I've always stuck with sftp (SSH), which is much more convenient, but it requires a unix/linux server, unfortunately windows doesn't handle it to my knowledge, although we now have an ssh client, why not a server.

the windows server client, OK, what is your server running on?

0