简体   繁体   中英

Where is error in ftp-bat script?

I scripting automatic ftp script.

And throws error:

The syntax of the command is incorrect.

User (domain.lt:(none)):

Error reading password.

Login incorrect.
Login failed.

Code:

@ECHO OFF
mkdir C:/dtmp
ECHO USER username > script.ftp
ECHO PASSWORD password > script.ftp
ECHO cd Directories-files > script.ftp
ECHO lcd C:/dtmp > script.ftp
ECHO binary > script.ftp
ECHO prompt n > script.ftp
ECHO get main.py > script.ftp
:: Use the temporary script for unattended FTP
:: Note: depending on your OS version you may have to add a '-n' switch
FTP -v -s:script.ftp domain.lt
:: For the paranoid: overwrite the temporary file before deleting it
TYPE NUL >script.ftp
DEL script.ftp
GOTO End
:End

You have a few immediate problems I can see.

The first is the use of the wrong slash in your mkdir command (and that's the one causing your specific error). It should be:

mkdir c:\dtmp

The second problem is the fact that you should be appending most of those commands to the FTP script:

ECHO USER username         > script.ftp
ECHO PASSWORD password    >> script.ftp
ECHO cd Directories-files >> script.ftp
ECHO lcd C:/dtmp          >> script.ftp
ECHO binary               >> script.ftp
ECHO prompt n             >> script.ftp
ECHO get main.py          >> script.ftp

The way you have it, every echo replaces the file, so the script will end up consisting of the single line get main.py which won't work because you haven't logged in.

Thirdly, since you're logging in within the script, you should disable auto login as well, by using the -n option to ftp (though I see that's mentioned in a comment after a closer look):

ftp -n -v -s:script.ftp domain.lt

Another thing to look at is the fact that some FTP clients don't have a PASSWORD command, they supply it on the USER line. So try changing:

ECHO USER username         > script.ftp
ECHO PASSWORD password    >> script.ftp

to:

ECHO USER username password > script.ftp

(and ensuring that your username and password are correct of course).

Failing that, simply start up an FTP session without the -s and see what's going wrong by entering each of the FTP commands individually:

C:\Pax> ftp -n wopr.dod.gov
Connected to wopr.dod.gov.
220-FTPD DOD FTP at WOPR.DOD.GOV, 07:28:59 on 2011-08-19.
220 SHALL WE PLAY A GAME?
ftp> user sfalken joshua
331 Send password please.
530 PASS command failed
Login failed.
ftp> bye
221 Quit command received. Goodbye.

Watch out for trailing spaces on the user/password when creating the FTP script file eg

ECHO USER username > script.ftp

Should be: ECHO USER username> script.ftp

Try the following

ftp -n wopr.dod.gov
user sfalken
pass joshua
bye

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM