Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

Is it possible to:

  1. execute sftp command on remote machine and download a file (ssh user@machine, sftp user2@server, get file)
  2. then, send download to background, so I can turn my local computer off
share|improve this question
Please correct me if i'm wrong: 1)You are connected locally on machine A. 2)You want to connect through SSH on machine B. 3)On B's shell, you want to execute a remote sftp download from machine C. 4)You then want do shutdown machine A. Is that correct? – Pavlos G. Dec 13 '10 at 15:48
A - my local computer; B - remote server 1; C - remote server 2; I want to type ssh user@B on my A machine, then sftp user@C and get some_file.tar.gz on B machine; so, I would like to sftp download a file from C to B and shut down my A machine, leaving remote B and C running – Paweł Karpiński Dec 13 '10 at 15:54
up vote 8 down vote accepted

Try screen on machine B, start the download and detach afterwards:

On machine A:

ssh user@B

On machine B:

sftp user@C
get some_file.tar.gz
Ctrl-a d

Never tried but could work.

Edit: later, log back in and use screen -x to reconnect to the running session. Then, shut it down properly so that it isn't consuming the server's resources.

share|improve this answer
it works! thanks a lot :) extremely useful command... – Paweł Karpiński Dec 13 '10 at 16:08
and for a funkier screen on ubuntu, try out byobu. – finley Dec 23 '10 at 12:25

If you just want the "detach" feature of screen, there's a program called "dtach" that provides only that feature.

share|improve this answer

Putting the character & (ampersand) behind a command runs it in background. However, I don't know how to do it after a command has already been executed, nor do I know whether this works on remote machines.

share|improve this answer
& would be OK, but I don't know any --password option I can pass through command line (so I can't do something like sftp --password=abc user@server:file.tar.gz &) – Paweł Karpiński Dec 13 '10 at 15:57

There are a number of solutions to this issue.

One option is to use the screen command, however seems a little complex.

The best way I have found is sending the job to the background.

In your case the command would be

scp user@machine:~/filename.ext /tmp &
scp -r user@machine:~/dirname /tmp &
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.