如何使用 sftp 批处理文件发送密码 [英] How to send password using sftp batch file
本文介绍了如何使用 sftp 批处理文件发送密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用批处理脚本从 sftp 站点下载文件.我收到以下错误:
I'm trying to download a file from sftp site using batch script. I'm getting the following error:
Permission denied (publickey,password,keyboard-interactive).
Couldn't read packet: Connection reset by peer
运行命令时:
sftp -b /home/batchfile.sftp <user>@<server ip>:<folder>
batchfile.sftp
包含这些数据:
password
lcd [local folder]
cd [sftp server folder]
get *
bye
注意:在提示符下运行时它正在工作
Note: It's working when running at the prompt as
sftp <user>@<server ip>:<folder>
但我需要能够自动输入密码.
But I need the ability to enter the password automatically.
推荐答案
您需要安装 sshpass 程序.那么:
You'll want to install the sshpass program. Then:
sshpass -p YOUR_PASSWORD sftp -oBatchMode=no -b YOUR_COMMAND_FILE_PATH USER@HOST
显然,最好设置公钥认证.仅在无论出于何种原因无法执行此操作时才使用它.
Obviously, it's better to setup public key authentication. Only use this if that's impossible to do, for whatever reason.
这篇关于如何使用 sftp 批处理文件发送密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文