In this script we are going to use the shell expect to perform a file transfer using SFTP.
We already have the keys generated and the user has passwordless access to the server, but the private key is protected by passphrase.
text
#!/usr/bin/expect -f
spawn sftp -P 11344 user11sftp01@192.168.1.158
expect «Enter passphrase for key ‘/root/.ssh/id_rsa’:»
send «c0ntr4s3n4\n»
expect «sftp>»
send «cd /out\n»
expect «sftp>»
send «mget *.txt\n»
expect «sftp>»
send «exit\n»
interact
system chown rokitoh:rokitoh /sftp/outAll the best
:wq!
Comments