Terminus by Warp
Copy File From Remote To Local Using Scp

Copy File From Remote To Local Using Scp

Razvan Ludosanu
Razvan Ludosanu
Founder, learnbackend.dev

The short answer

To copy and download a file from a remote server to your local machine, you can use the `scp` (secure copy) in the following way:

 $ scp <user>@<host>:<source> <destination>

Where:

  • [.inline-code]user[.inline-code] is your username on the remote server.
  • [.inline-code]host[.inline-code] is the IP address or the hostname of the remote server.
  • [.inline-code]source[.inline-code] is the path of the file you want to copy on the remote server.
  • [.inline-code]destination[.inline-code] is the destination path of the file you want to copy on your local machine.

When executing this command, you will be prompted to enter the password of the specified user account on the remote server.

For example, the following command will attempt to copy the [.inline-code]index.js[.inline-code] file located in the [.inline-code]/home/john/app[.inline-code] directory on the remote server to your home directory on your local machine using the [.inline-code]johndoe[.inline-code] account.

 $ scp johndoe@127.0.0.1:/home/johndoe/app/index.js ~/index.js

[#recall-syntax]Remind yourself of the syntax using AI Command Search[#recall-syntax]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Entering [.inline-code]copy file from remote server to local machine[.inline-code] in the AI Command Search will suggest you the correct [.inline-code]scp[.inline-code] command, which you can then quickly insert into your shell by doing [.inline-code]CMD+ENTER[.inline-code].

[#scp-multiple-files][.inline-code]scp[.inline-code] multiple files at once[#scp-multiple-files]

To copy multiple files located in the same directory on the remote server at once, you can either use a wildcard pattern:

 $ scp <user>@<host>:/path/to/directory/* /path/to/local/directory

Or a brace expansion:

 $ scp <user>@<host>:/path/to/directory/{file_1,file_2} 
 /path/to/local/directory

[#scp-folder][.inline-code]scp[.inline-code] an entire folder from remote to local[#scp-folder]

To copy an entire folder and all of its content including subdirectories, you can use the [.inline-code]-r[.inline-code] flag (short for recursive):

 $ scp -r <user>@<host>:/path/to/directory /path/to/local/directory

Note that when using this command, the source directory will be copied from the remote server within the specified destination directory on the local machine.

For example:

 $ scp -r johndoe@127.0.0.1:/home/johndoe/app ~/Projects
 $ ls ~/Projects
 app

[#scp-remote-to-local][.inline-code]scp[.inline-code] to your local machine while being connected to a remote machine via [.inline-code]ssh[.inline-code][#scp-remote-to-local]

Although it is unusual, the [.inline-code]scp[.inline-code] command can be used to copy files from a remote server to the local machine whilst being connected to the remote server.

To do so, you must first connect to the remote server using the [.inline-code]ssh[.inline-code] command:

 $ ssh <user>@<host>

Where:

  • [.inline-code]user[.inline-code] is your username on the remote server.
  • [.inline-code]host[.inline-code] is the IP address or the hostname of the remote server.

Which will prompt you to enter the password of the specified user account on the remote server.

Once connected, you can use the following syntax:

 $ scp /path/to/file ${SSH_CLIENT%% *}:/path/to/local/file

Where:

  • [.inline-code]${SSH_CLIENT%% *}[.inline-code] will be replaced by the IP address of the client connected to the remote server (i.e. your machine) using a parameter substitution symbolized by the [.inline-code]${}[.inline-code] expression.

Note that for this to work, you will need to run an SSH server on your local machine and set up an SSH account in order to allow remote connections.

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.