Last updated on February 21st, 2022 at 07:33 am
Getting the password to the ftp server without having the ftp client program read the password from /dev/tty requires two tricks:
- Using the -n option on the ftp client program to prevent the ftp client from trying to log in immediately. That way, the ftp client does not ask for a user ID and password. No use of /dev/tty.
- Use the ftp client program command quote to send user ID and password to the ftp server.
- The fileĀ /dev/tty is a character file with major number 5 and minor number 0, usually of mode 0666 and owner.group root.tty.
- /dev/tty helpsĀ output displayed to the (terminal)
- In this we are copying file named “file.txt” to the server in location /databasebackup/DB
#!/bin/sh
HOST='ftp.yourserver'
USER=''
PASSWD=''
FILE='file.txt'
ftp -n $HOST << END
quote USER $USER
quote PASS $PASSWD
cd /databackup/DB/
put $FILE
quit
END
exit 0