This is my script. As you can see it executes only 1 command (cd /) after connecting to a remote FTP server. It's very simple... but it doesn't work and give me "Invalid command".

I don't understand why.


HOST=xxx             #This is the FTP servers host or IP address.
USER=xxx                     #This is the FTP user that has access to the server.
PASS=xxx              #This is the password for the FTP user.

# Call 1. Uses the ftp command with the -inv switches. 
#-i turns off interactive prompting. 
#-n Restrains FTP from attempting the auto-login feature. 
#-v enables verbose and progress. 

ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.

user $USER $PASS


# Call 3. I change to the directory where I want to put or get
cd /

# Call4.  Here I will tell FTP to put or get the file.

# End FTP Connection


This is the output:

Connected to [IP]
220 Microsoft FTP Service
?Invalid command
331 Password required for logweb.
230 User logged in.
Remote system type is Windows_NT.
Passive mode on.
?Invalid command
250 CWD command successful.
?Invalid command
?Invalid command
?Invalid command
221 Goodbye.

The "Invalid command" error is due to those # lines. The ftp does not recognize the # as a comment prefix.

If you need the comments in the script, you can abuse an escape to shell command ! and follow that by a shell comment:

!# This is comment

Other than that, I believe all commands in your script are executed, despite your claim that only one is:

> user $USER $PASS
< 331 Password required for logweb.
< 230 User logged in.

> cd /
< 250 CWD command successful.

> bye
< 221 Goodbye.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.