Because of technical limitations on a pair of platforms I’m using at work, I am unable to set-up key-based SFTP or SCP to transfer files between the pair of them, so I knocked together this short script using the TCL based Expect language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
set arg1 [lindex $argv 0] | |
set arg2 [lindex $argv 1] | |
set arg3 [lindex $argv 2] | |
set timeout 1000 | |
spawn sftp "$arg2" | |
expect { | |
yes { | |
send "yes\r" | |
exp_continue | |
} | |
ass { | |
send "$arg3\r" | |
exp_continue | |
} | |
sftp { | |
send "put $arg1\r" | |
expect { | |
100% { | |
send "quit\r" | |
exp_continue | |
} | |
} | |
} | |
} |
There’s no error checking here, which isn’t great, but as a quick-and-dirty script to SFTP files to a box which needs the password each run… it works! :)