简体   繁体   中英

FTP script not working

I have an FTP script running on Linux and it is failing. Here is the script:

/usr/bin/ftp -v -i -n my.ftp.server << cmd
user ftpuser password 
binary 
ls 
<some other commands here>
quit cmd

It returns an error:

421 Service not available, remote server has closed connection 
Not connected.

The weird thing here is that if I just typed this in the command line: /usr/bin/ftp my.ftp.server It asks for a username and password and after I supplied them, I was able to connect!

In ftp> I type ls and I can see the files from the FTP server. What is wrong with my script?

And also, I don't have putty access to the FTP server so I can't see the logs from there. Any ideas?

Thanks!

Here is an example of a correct ftp linux script.

#!/bin/sh
HOST='ftp.server.com'
USER='user'
PASSWD='pw'
FILE='file.txt' #sample file to upload

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE #sample command
#some other commands here
quit
END_SCRIPT
exit 0

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