scripting sftp with expect -
i have script sftp-access password-authentification. unfortunately our client can't create key-authentification on server have access.
all sftp-commands generated , written in temporary file (tmp.txt). next command works fine on command-line:
sftp onlineregtest_bs@ftp.b-n-c.ch < tmp.txt the problems starts when i'd utilize "expect" because have script , utilize password.
expectscript=`cat <<eof spawn sftp user@server < tmp.txt expect "password" send ${pass} send "\r" eof` expect -c "$expectscript" if remove "< tmp.txt" connection establish. need commands tmp.txt. here's error-message:
[root@xxx web]# ./transfer.sh spawn sftp user@server < tmp.txt usage: sftp [-1cv] [-b buffer_size] [-b batchfile] [-f ssh_config] [-o ssh_option] [-p sftp_server_path] [-r num_requests] [-s program] [-s subsystem | sftp_server] host sftp [[user@]host[:file [file]]] sftp [[user@]host[:dir[/]]] sftp -b batchfile [user@]host send: spawn id exp6 not open while executing "send password" does have ideas?
i couldn't running sftp -b... :-(
edit @glenn jackman
expectscript2=`cat <<eof spawn sh -c {sftp user@server < tmp.txt} expect "password" send ${pass} send "\r" expect "sftp>" expect "sftp>" ..... expect "sftp>" expect "sftp>" expect "sftp>" eof` the tmp.txt looks this:
cd d set d/d1 cd ../e set e/e1 set e/e2 cd ../f set f/f1
try spawning shell handle redirection:
spawn sh -c {sftp user@example.com < tmp.txt} sftp expect spawn
No comments:
Post a Comment