Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

SFTP transfer script with expect

Leer en espanol
SFTP transfer script with expect

Table of contents

We already have the keys generated and the user has passwordless access to the server, but the ===

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/out

All the best

:wq!

Comments