0

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

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

knl
  • 127

1 Answers1

0

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

scp /local/file/path root@192.168.1.xxx /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 user@192.168.1.xxx:/home/user/some/path
ssh user@192.168.1.xxx
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

Rumesh
  • 1,439
  • would i be able to cron the sudo mv stage, given the need to enter a password? – knl Jun 06 '15 at 03:29
  • maybe, I am not really familiar with cron so I do not know if that is possible. However, if you do not want to enter the password, you can edit your sudoers file. You can see http://askubuntu.com/a/612706/399217 to see how to edit the sudoers file. – Rumesh Jun 06 '15 at 03:33
  • when I try root@192 ... and enter the password for the remote computer, I get permission denied. I've tried entering the password enough times it's not a typo issue or the like. Any idea? – knl Jun 06 '15 at 04:18
  • I suspected that would be the case, openssh does not allow root access by default. You will have to edit some settings to ssh as root but this is advisable as it is a security risk – Rumesh Jun 06 '15 at 04:35
  • I have updated my answer to include a script you run to move the files – Rumesh Jun 06 '15 at 05:10
  • hmm ok. What would be the best way to add such a script to startup, since it will always be running? – knl Jun 06 '15 at 08:36
  • does the remote computer have a GUI and do you have access to it? – Rumesh Jun 06 '15 at 08:39
  • I have access to the GUI right now, but that may not always be the case. – knl Jun 06 '15 at 08:49
  • In that case, open the dash and type startup applications, click add and enter the name and path to the file. I would recommend you to put the script in /usr/local/bin/. – Rumesh Jun 06 '15 at 09:36
  • i was able to get the script going on startup as you said, altho your script isn't working for me. – knl Jun 07 '15 at 03:42