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
  • 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
    – Praweł
    Dec 13 '10 at 15:54

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.

  • it works! thanks a lot :) extremely useful command...
    – Praweł
    Dec 13 '10 at 16:08
  • and for a funkier screen on ubuntu, try out byobu.
    – finley
    Dec 23 '10 at 12:25
  • work like a charm Oct 7 '21 at 13:06

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


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.

  • & 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 &)
    – Praweł
    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 &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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