3

Motivation: owncloud-client fails periodically because of many reasons; I need scp during those events. In server, ls -la at $HOME

drwxr-xr-x 2 masi masi 4096 May 31 14:14 .
drwxr-xr-x 4 root root 4096 May 31 10:18 ..
-rw------- 1 masi masi 1099 May 31 12:20 .bash_history
-rw-r--r-- 1 masi masi  220 May 31 10:18 .bash_logout
-rw-r--r-- 1 masi masi 3512 May 31 10:18 .bashrc
-rw-r--r-- 1 masi masi  675 May 31 10:18 .profile
-rw------- 1 masi masi 2632 May 31 14:14 .viminfo

I can

  • ssh masi@192.168.1.101

I cannot for some reason

  • scp $HOME/5GBdata/ masi@192.168.1.101:$HOME/

Where to SCP files?

Server: Raspberry Pi 3b. Client: Ubuntu 16.04.

Review of Ankit's answer

Client-side

masi@masi:~/Documents/Masi$ rsync -avz Directory -e ssh masi@192.168.1.107:/home/masi/
sending incremental file list
Directory/
Directory/common_mistakes.tex

sent 484 bytes  received 58 bytes  63.76 bytes/sec
total size is 4,143  speedup is 7.64

Server-side

masi@raspberrypi:~ $ ls Directory/
common_mistakes.tex
masi@raspberrypi:~ $ sudo cp -r /home/masi/Directory /var/www/owncloud/data/masi/files/

masi@raspberrypi:~ $ sudo -u www-data php /var/www/owncloud/occ files:scan masi 
Scanning file   /masi/
Scanning folder /masi/
... 
Scanning file   /masi/files/Directory
...
Scanning folder /masi/files/Directory
Scanning file   /masi/files/Hematology/._common_mistakes.tex
Scanning file   /masi/files/Hematology/common_mistakes.tex
...
Scanning folder /masi/cache

where you have to have a complete path to occ. It works!

2 Answers2

6

Prerequisites:

  1. Data directory on the Owncloud server : Connect to server via ssh.If you have installed owncloud server to default location (/var/www), then go to the config file to find about the data directory location.

nano /var/www/owncloud/config/config.php

This file will tell you the location of the data directory (the place where all the files are stored.). Like this; Config.php file of owncloud

Now the Solution:

First, you can transfer the folder to the server using rsync and ssh. Its most convenient and fast (since compression is included). For example, from the local computer on the terminal use,

rsync -avz /path/to/local/50GBfolder -e ssh username@address:/home/user

Next, connect to server using ssh and from there copy folder to the owncloud data directory. (Two step are needed since you need root permission to copy to owncloud data directory which is owned by www-data user.)

Copy files this way;

sudo cp -r /home/user/50Gbfolder /path/to/data/$owncloud_username/files/

  • Inside the data directory, there is a folder for each owncloud user as owncloud_username, then under that there is a folder as files; hence mentioned above in the command.

Lastly, update owncloud database by scanning to identify the new files. This is done by prebuilt command. First, change directory to your owncloud installation directory. For default this is \var\www\owncloud. so,

cd \var\www\owncloud

If you do ls, you will see an executable as occ under this folder. This occ is a php based program.

To run occ for rescan,

sudo -u www-data php occ files:scan $user_name

Full rescan may take some time. After the rescan, you will see the folder when logged in from a browser.


Explanation:

  • rsync -avz /path/to/local/50GBfolder -e ssh username@address:/home/user

-a includes recursive, permissions, links, group etc and much more. Check man-page. -v verbose, -z compress and transfer.

  • sudo cp -r /home/user/50Gbfolder /path/to/data/$owncloud_username/files/

-r recursive folder copy, all subfolders are copied.

ankit7540
  • 4,195
2

There are two problems with your scp command:

  • You are trying to upload a directory, hence you must provide the -r option (copy recursively).

  • The environment variables are substituted before the execution of the command. Therefore, $HOME in masi@192.168.1.101:$HOME/ expands to the path of your home directory on your local (rather than the remote) machine. If the home directory paths on the two machines are different then the command will work not as you intended, most probably failing because of access problems. When using scp, refer to your home directory on the remote machine with '.' (in other words scp interprets paths on the remote machine relative to your home directory).

So the correct command will be:

scp -r $HOME/5GBdata/ masi@192.168.1.101:.

However, note that this answer only points out your mistakes in using scp. Refer to the other answer(s) for recommendations on how to achieve your final goal.

Leon
  • 121