Use scp to transfer a file from local directory X to remote directory Y

You need to run the scp command from the local machine, not on the remote. You don't need the ssh at all:

dragonmnl@local $ scp -P 2222 file.ext username@domain:~/ 

You also don't need the -r:

 -r      Recursively copy entire directories.  

If you are already logged into the remote machine and want to copy from your local, you need to make sure that your local machine is accessible via the internet and has ssh set up. I don't think this is what you are after but if it is, just run this from the remote:

username@domain $ scp dragonmnl@local:/path/to/file.ext ~/

I provide two methods of up/down load file between remote and local machine(I use Mac air):

In this case, I want to up/down 11.jpeg between local and remote:

  1. Copy files on service to local dir: You must be in local bash terminal to conduct this command, not when you are in ssh!

    scp username@domain:/home/xxx/xxx/11.jpeg /Users/username/Desktop/   
    

    copy files in local dir to remote service : also you must be in local bash terminal

    scp /Users/username/Desktop/11.jpeg username@domain:/home/xxx/xxx
    
  2. To achieve the same intention when you are logging in the SSH, you must first set “System Preferences>sharing>remote log in>all users(I am not sure if you must set for "all users", but it works in this situation)” the Mac will tell you"To log in to this computer remotely, type:

    ssh username@xxxxxx, then type in the command below:
    scp username@domain:/home/xxx/xxx/11.jpeg username@xxxxxx:/Users/username/Desktop/**
    

This command above is for downloading file from remote to local when you are logging into ssh, Just change the two path when you want to upload file .


Use the scp command

If you want to transfer a folder, just zip it first, we can unzip it later on.

From your computer, run this:

$ scp your_path_to_the_file/the_file [email protected]:~/

Here, root is your account, and 10.145.198.100 is the remote server's IP address. We're going to copy the_file to ~/ folder in the remote.

Unzip file:

$ unzip the_zip_file.zip -d destination_folder

Tags:

Scp