sftp script without Expect

We are trying to create an sftp (or lftp) script on a cloud-based server.  There are two things that are complicating this:
1. The cloud-based host does not allow "expect" to be installed
2. The remote host has our ssh key installed on it.  Any SFTP or LFTP connection is requiring that I enter the passphrase for the key.
2a. The remote host still requires a password for an SFTP connection, even with the ssh key installed.

I'm trying to figure out how to write a script that will send the passphrase and the password to authenticate, and then send files to the remote server.

Any help would be greatly appreciated!


Dan PackerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
1) Don't use expect. It's overkill.

2) Use BASH or PERL or whatever scripting language is available.

3) To execute sftp commands, create an empty passphrase key + use as follows (after you deploy the public key just like ssh).

echo "$command\n$command\nquit\n" | sftp -i ~/path-to-private-key root@yourhost.com:remote-file-path local-file path

Open in new window

Note: I transfer Terrabytes of data between machines, so strongly suggest your use rsync, rather than sftp, as rsync transfers will be far less error prone.
Dan PackerAuthor Commented:
Thanks - my server doesn't support the -i flag - is there some alternate syntax that I can use?
Duncan RoeSoftware DeveloperCommented:
The trick would be to somehow send the user name and then delay for a bit before sending the password. (s)ftp flushes the terminal input buffer before issuing the Password: prompt. By delaying, you give the prompt time to appear. Would need to know more about your setup to advise further, e.g. how are you communicating with the sftp host.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan PackerAuthor Commented:
Thank you for your help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.