SSH SCP Local file to Remote in Terminal Mac Os X

command linescpsshterminal

I am attempting to copy a local file 'magento.tar.gz' from my local machine to a remote server using SSH through a VPN. This is connecting to the Virtual Machine's Internal IP which I've used as xx.x.x.xx here.

I have full 'sudo' access on the SSH account so there shouldn't be any problem copying across. I have tried the following:

I have tried the following (the magento.tar.gz file is already in the local root dir)

sudo scp magento.tar.gz user@xx.x.x.xx/var/www/

This asks me to type in my local password. Afterwards returns cp: user@xx.x.x.xx/var/www: Not a directory

sudo scp /Users/myname/magento.tar.gz user@xx.x.x.xx/var/www/

Returns the same.

Do I need to include a SSH in there anywhere?

Do I need to connect via SSH to the site first?

Side note: I've managed to connect via SSH to the server, browse to the directory and make a folder and delete it using sudo mkdir etc so I definitely have permissions.

Best Answer

At first, you need to add : after the IP address to indicate the path is following:

scp magento.tar.gz user@xx.x.x.xx:/var/www

I don't think you need to sudo the scp. In this case it doesn't affect the remote machine, only the local command.

Then if your user@xx.x.x.xx doesn't have write access to /var/www then you need to do it in 2 times:

Copy to remote server in your home folder (: represents your remote home folder, use :subfolder/ if needed, or :/home/user/ for full path):

scp magento.tar.gz user@xx.x.x.xx:

Then SSH and move the file:

ssh user@xx.x.x.xx
sudo mv magento.tar.gz /var/www
Related Topic