【问题标题】:Giving the user password in a script在脚本中提供用户密码
【发布时间】:2023-09-26 19:10:01
【问题描述】:

我制作了一个允许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 添加用户密码?...

【问题讨论】:

    标签: bash shell scripting ftp


    【解决方案1】:

    一个例子:

    #!/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
    

    【讨论】:

      【解决方案2】:

      这取决于 ftp 版本。 有时版本允许提供用户名和密码以及主机名:

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

      还有两个 ftp 命令允许传递凭据 (man 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.
      

      【讨论】:

        最近更新 更多