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:

  1. 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.
  2. Use the ftp client program command quote to send user ID and password to the ftp server.
  3. 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.
  4. /dev/tty helpsĀ output displayed to the (terminal)
  5. 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

Leave a Reply

Your email address will not be published. Required fields are marked *