We need a script that can send username / password in our Linux Box to transfer files through SFTP or SCP.
Requirement
1. OpenSSH
2. Expect
Illustrations :
We want to get "passwd" file on Server-A (192.168.1.1) and saved to /home/dianseh/passwd-Server-A on Server-B (192.168.1.2).
The script is :
---- Script Start -----
#!/usr/bin/expect --
#spawn sftp dianseh@192.168.1.1:/etc/passwd /home/dianseh/passwd-Server-A
spawn scp dianseh@192.168.1.1:/etc/passwd /home/dianseh/passwd-Server-A
expect "dianseh@192.168.1.1's password:"
send "passwordnya\r"
expect "%$"
---- Script End -----
Note :
Let me know if it's working.
Good Luck
为某些程序自动输入密码
最新推荐文章于 2024-06-25 19:27:26 发布