Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have 5 servers running our code: A, B , C, D and E.

From a local machine, we sftp the file to A. Then

ssh id@A
su - applicationname
sftp id@A
get <file>
tar -xzf <file>

The same procedure we apply for others B to E.

Is there any way we can simplify this using script?

We have requested linux team to provide passwordless authentication. But we don't know how to do sftp inside a SSH session using a script.

share|improve this question
Use scp instead. – jordanm Nov 18 '12 at 17:50

Best and easiest is to use scp instead of sftp.

If scp is really not an option, you can read sftp commands using a 'here document', but it is very hard to script around errors.

sftp username@server << %EOF%

%EOF% can be any word you want, as long as it starts and ends with a % and the last %EOF% must be at the start of a line.

For passwordless login, read up on 'ssh key authentication'.

Using sftp from within an ssh session sounds like overkill, sounds like doing double things. Why not initiate the copy from the local machine?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.