So, you have scp transfer (from one remote server to another), that is quite big.

And your big question is:

Does a `scp` transfer close when I close the shell?

There are a number of solutions.

cpanel terminal



Background & Disown the Process

  1. Open ssh terminal to remote server.
  2. Begin scp transfer as usual.
  3. Background the scp process (Ctrl+Z, then the command bg.)
  4. Disown the backgrounded process (disown).
  5. Terminate the session (exit) and the process will continue to run on the remote machine.


One disadvantage to this approach is that the file descriptors for stdout and stderr will still contain references to your ssh session's tty. The terminal may hang when you try to exit because of this. You can work around this by typing ~. to force close your ssh client (that escape sequence must follow a new line...see also ~?). If the process you are abandoning writes to stdout or stderr, the process may exit prematurely if the tty buffer overfills.


Create a Screen Session and Detach It

GNU Screen can be used to create a remote terminal session, which can be detached and continue to run on the server after you log out of the session. You can then log back into the server at a later date and reattach to the session.


  1. Log into the remote server over ssh.
  2. Start a screen session, screen -D -R <session_name>.
  3. Begin scp transfer as usual.
  4. Detach the screen session with Ctrl+A then d.
  5. Terminate the ssh session (exit)


To reattach to the session:

  1. Log into the remote server over ssh.
  2. Reattach to the screen session, screen -D -R <session_name>

Run the Command without Hangups

See the answer using nohup.


Use a Task Scheduler

This is the best solution if this is a periodic sort of task that you want to automate.

Use crontabat, or batch to schedule the transfer.

Post a Comment

Previous Post Next Post