在脚本中提供用户密码

时间:2015-05-09 05:25:00

标签: bash shell scripting ftp

我制作了一个允许ftp登录的脚本。但我不知道如何为用户添加密码

#!/bin/bash


 if grep -q $1 "/opt/proftpd.conf"; then
   echo "$1 is an ftp user"


HOST='192.168.1.212'
USER=''$1''
 FILE=''$2''

ftp -n -v $HOST <<END_SCRIPT

quote USER $USER
put $FILE
quit
END_SCRIPT
ls -la /home/$1

exit 0
 else
  echo "$1 is not an ftp user"
 fi
exit 0

如何为ftpuser添加用户密码?...

2 个答案:

答案 0 :(得分:0)

这取决于ftp版本。 有时版本允许将用户和密码与主机名一起提供:

ftp://[user[:password]@]host[:port]/path

还有两个允许传递凭证(man ftp)的ftp命令:

 account [passwd]
     Supply a supplemental password required by a remote system
     for access to resources once a login has been successfully
     completed.  If no argument is included, the user will be
     prompted for an account password in a non-echoing input mode.

 user user-name [password] [account]
     Identify yourself to the remote FTP server.  If the password
     is not specified and the server requires it, ftp will prompt
     the user for it (after disabling local echo).  If an account
     field is not specified, and the FTP server requires it, the
     user will be prompted for it.  If an account field is speci-
     fied, an account command will be relayed to the remote server
     after the login sequence is completed if the remote server
     did not require it for logging in.  Unless ftp is invoked
     with "auto-login" disabled, this process is done automati-
     cally on initial connection to the FTP server.

答案 1 :(得分:0)

一个例子:

#!/bin/bash

ftp_host="192.168.1.212"
ftp_user="$1"
ftp_file="$2"

read -s -p "Enter password for user ${ftp_user}: " ftp_pass

ftp -n -v ${ftp_host} << EOF
 quote USER ${ftp_user}
 quote pass ${ftp_pass}
 bin
 put ${ftp_file}
EOF