Scp to /Media Directory

I can scp to a directory under /home but not under /media. Why?

So for example scp /local/file/path /home/more/path works but scp /local/file/path /media/more/path does not.

1 Answer

You need to have root access to scp to that directory. So you can try

scp /local/file/path  /media/more/path

If that does not work you would have to scp to somewhere in the home directory and then move it to the /media directory. You could also do this through ssh if you know the root password.

scp /local/file/path :/home/user/some/path
ssh 
sudo mv /some/path/file /media/

You can also use a script to move the file to /media directory when you scp a file to the remote machine. You can use the following script.

#!/bin/bash

while true
do
    sleep 10
    contents=$(ls -A /home/user/directory)
    if [ $contents ]
    then
        sudo mv /home/user/directory/* /media/
    fi
done

I would recommend you to have an empty directory into which you can copy the files to. The script will move the contents of the directory to /media/ every 10 seconds. You can use different numbers after sleep depending on the frequency you want the script to run. You will still have to enter the password to move the files however, If you do not want to enter the password, see this answer.

Note: If the number is too small, It may affect your computers performance depending on the hardware

11

Your Answer

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

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest