0

我正在尝试将 txt/ 日志文件从 server1 移动到 server2。

我正在尝试使用 SFTP 连接到从 server1 到 server2 的服务器,但它是如何在提示中要求输入密码的。谁能告诉我如何通过脚本输入密码并使用脚本执行此功能。请尽快告诉我......

我的代码:

test.sh 是脚本,1.txt 文件有密码详细信息.....

代码:test.sh sftp mwctrl@sacsun11 < 1.txt <> out.log 2>&1 cd /usr/ftadapters/logs/adapters/rivaadp lcd /export/home/eisape put *.txt exit EOF

1.txt:密码m33tzn3

4

3 回答 3

2

实际上,您需要将 ssh 密钥添加到远程机器。检查下面的文章:

使用没有密码的 sftp (http://says-story.blogspot.nl/2008/01/using-ssh-scp-sftp-without-password.html)

于 2012-08-09T09:49:10.457 回答
0

设置 ssh 密钥相对简单。按照fxzuz上面发布的链接中的说明进行操作,花费不到1 分钟。

但通常将密码作为参数传递/存储在配置文件中被认为是一种安全风险。

但是,如果您仍然想继续,这里有一个链接——http: //nixcraft.com/shell-scripting/4489-ssh-passing-unix-login-passwords-through-shell-scripts.html

于 2012-08-09T16:13:16.187 回答
0

尝试使用这个

/usr/bin/expect <<EOF
spawn sftp -oStrictHostKeyChecking=no -oCheckHostIP=no mwctrl@sacsun11 \
"cd /usr/ftadapters/logs/adapters/rivaadp \
lcd /export/home/eisape \
put *.txt \"
expect "*?assword:*"
send  "m33tzn3"
send  "\r"
set timeout -1
send  "\r"
expect EOF
于 2012-08-10T07:10:59.700 回答