Reputation: 21
I am trying to transfer a file from one server to a remote server using SFTP. Client is not ready for key setup so I have gone through other questions on this forum related to SFTP and tried all. But still its not working in my case.
My Script :-
#!/bin/sh
# sample automatic ftp script to dump a file
USER="username"
PASSWORD="password"
HOST="hostname"
sftp $USER@$HOST << EOF
$PASSOWRD
cd test_path
put test_file.txt
quit
EOF
Upvotes: 1
Views: 33950
Reputation: 56
You can do this using expect
. It's very easy and simple;
#!/usr/bin/expect
spawn sftp <userid>@<server>
expect "password:"
send "<password>\n"
expect "sftp>"
send "cd <remot dirctory>\r"
expect "sftp>"
send "mput * \r"
expect "sftp>"
send "quit \r"
Upvotes: 2
Reputation: 99
Try the below steps,
lftp -u $user,$passwd sftp://$host << --EOF--
cd $directory
put $srcfile
quit
--EOF--
Upvotes: 1
Reputation: 14160
You have a misprint in your script - you are writing $PASSOWRD instead of $PASSWORD, so it substitutes empty string.
Upvotes: 9