# Trying to get my head around accessing a remote directory for file copying

**URL:** <https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769>\
**Category:** General\
**Created:** [22 September 2019 08:52 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769 "2019-09-22T08:52:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 08:52 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/1 "2019-09-22T08:52:58Z")

</div>

I know I have been down this road before, but slightly differently this time.

I have a script to backup node-red stuff _locally_ on the same machine.

As things go on, I am needing to now access a remote machine (probably a NUC, but who knows at this stage) and copy files from the machine to the remote machine.

It will be a USB drive and may not always be there.

I have the share set up on the remote machine.  
`showmount -e <ip address>` shows me the share.

So, how I am stuck _how_ to access that share.

Do I mount the share, or can I copy the files to the remote machine another way?  
If I have to mount it, it isn't too much of a problem, but it makes it slightly more complicated, but not impossible.

So for now I am wanting to understand the options of how to copy the files (directories?) between machines.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 September 2019 09:20 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/2 "2019-09-22T09:20:45Z")

</div>

ssh, scp, rsync or mount it.

There is a [node for rsync](https://flows.nodered.org/node/node-red-contrib-rsync), makes it easier to do in node-red (same goes for the backup btw, you can do that in node-red).

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 09:22 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/3 "2019-09-22T09:22:28Z")

</div>

I'm looking at `rsync` just now.

That saves on mounting the drive on the local machine.

Tried `dryrun` but it failed. ☹ Something about passwords.

I am copying to a shared directory, so I am not getting what's going on there.

Could you help me please?

This is the error:

```auto
Permission denied, please try again.Permission denied, please try again.Permission denied (publickey,password).rsync: connection unexpectedly closed (0 bytes received so far) [sender]rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]

```

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [22 September 2019 09:32 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/4 "2019-09-22T09:32:00Z")

</div>

What I do is more of the advanced route, but I have network shares in a SystemD unit file set up for mounting, including setting the permissions right. If needed I can control those through a `systemctl` command but most I’ve set up to automount once a network connection is present. These run on a pi that is connected over WiFi, so setting up mount points for those in `/etc/fstab` isn’t the right path as that will run before a network connection is present. So far it’s working good, and I’ve a feeling I should be able to get it working through a flow too, though I’m not there yet (for lack of trying mostly)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 09:36 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/5 "2019-09-22T09:36:02Z")

</div>

`fstab` is _parts unknown_ to me.

I can mount the drive/device/folder but as it is early days......

Also the machine to where they will be sent may not always be online and the folder also may not be there.

So: it is a bit complicated. I don't know how to do all those tricks yet.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 September 2019 09:36 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/6 "2019-09-22T09:36:35Z")

</div>

For remote backups I generally do it the other way round... and have the central "server" just go out to each client and copy the files back to itself at regular intervals using a simple loop and rsync - if one of the clients isn't there for some reason then it just moves on to the next.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 09:38 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/7 "2019-09-22T09:38:58Z")

</div>

That's a good idea. Thanks.

But then, the remote directory needs to be shared - yes?

All I know about sharing is that I edit the `/etc/exports` file and that shows up in the `showmount` command.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 September 2019 09:44 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/8 "2019-09-22T09:44:26Z")

</div>

rsync can be used for local backup creation, but the `r` in rsync stands for `remote`, usage:

`rsync options source destination`

There is always security in between, rsync has an environment variable available for supplying passwords (`RSYNC_PASSWORD`).

To make life easier, use [ssh key pairs between your devices](http://www.linuxproblem.org/art_9.html) so that you don't need to enter a password. (ie. generate key on the source device, copy the key to the remote device). Then you can use rsync over ssh.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 09:46 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/9 "2019-09-22T09:46:28Z")

</div>

Yes, I have keys between the machines. Though I think it is only one way. (Luckily it is the right way)

But there is a "master password" used so I don't have to remember umpteen passwords. Just one.

Will this cause problems?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 September 2019 09:48 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/10 "2019-09-22T09:48:34Z")

</div>

no - you can just scp in (or rsync) and copy the files from the remote directory. nothing needs to be mounted. As long as the remote user can a) login to the client computer and b) has permission to read the files in that directory then it should be fine. So in my case I log as "pi" user and use the required password, (or set up certificates - which to me is easier - but not for this thread).

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 09:53 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/11 "2019-09-22T09:53:47Z")

</div>

Yeah, I have all that set up.

Now just getting it working in the node.

Alas the errors are not helpful at this stage.

I am adopting your idea that the _sever_ gets the file from the remote machines.  
I can SSH to the remote machine/s ok - but I need to enter the master password - to log in.

In the `remote` machine field.....

This is the path:  
`192.168.0.93:/home/pi/Backups/NR/2019-09-15.16.59.29/`

But do I need it to be  
`pi@192.168.0.93:/home/pi/Backups/NR/2019-09-15.16.59.29/`?

Yeah, I'll be trying but just to disclose all things I am doing.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 September 2019 10:00 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/12 "2019-09-22T10:00:48Z")

</div>

typically an rsync command would look like

```
rsync -avz ssh pi@192.168.0.100:/home/pi/.node-red mylocalBackupDir1/
```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 10:16 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/13 "2019-09-22T10:16:33Z")

</div>

Ok, but if I am using the `node`, where does the -avz come in?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 10:23 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/14 "2019-09-22T10:23:57Z")

</div>

> [@dceejay](#):
>
> typically an rsync command would look like
> 
> ```auto
> rsync -avz ssh pi@192.168.0.100:/home/pi/.node-red mylocalBackupDir1/
> 
> ```

Um, sorry.  
Putting aside the IP number that doesn't work.

However if I try:  
`rsync -avz pi@192.168.0.93:/home/pi/.node-red /home/me/TEMP/NR/`

It works.

What is the need for the ` ssh` part? and the leading `/` on the local path. Is that needed too?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 September 2019 10:25 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/15 "2019-09-22T10:25:00Z")

</div>

> Ok, but if I am using the `node` , where does the -avz come in?

Linux has a nice command available for you if you don't understand what something does: `man` (manual)

`man rsync` and if you don't have it installed you can google for it.

> **[rsync(1) - Linux man page](https://linux.die.net/man/1/rsync)**
>
> Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync ...

> What is the need for the `ssh` part? and the leading `/` on the local path. Is that needed too?

You need to copy it to a remote location, you need ssh for that. Yes you need the `/`, the concept: `@host` 'mount point' `:` directory `/`

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 10:31 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/16 "2019-09-22T10:31:47Z")

</div>

Yes, but . . . . .

The example is for "cli" use. I get that. But I seem to remember it being pointed out that there is a `rsync` node for NR which _simplifies_ the use.

I was trying to use the `rsync` node.

So using what @dceejay posted I tried it from a CLI. Error.

Modifying it to what I posted, it works.

I don't get how @dceejay could make that kind of mistake.  
(Not blaming.) But it threw a spanner in the works.

So I can get it to work from the CLI, but then I would use/need the `exec` node.  
As there is a `rsync` node, why not use it?

But I didn't see where the `-avz` bit gets _written in to_ the command.

This is what happens:

```auto
me@me-desktop:~/TEMP/NR$ rsync -avz ssh pi@192.168.0.93:/home/pi/.node-red home/me/TEMP/NR/
Unexpected remote arg: pi@192.168.0.93:/home/pi/.node-red
rsync error: syntax or usage error (code 1) at main.c(1361) [sender=3.1.2]
me@me-desktop:~/TEMP/NR$ 

```

Changing only the source path I get this:

```auto
me@me-desktop:~/TEMP/NR$ rsync -avz pi@192.168.0.93:/home/pi/TEMP /home/me/TEMP/NR/
receiving incremental file list

sent 25 bytes received 115 bytes 93.33 bytes/sec
total size is 661 speedup is 4.72
me@me-desktop:~/TEMP/NR$ 

```

So, I don't get why it doesn't work.

Ok, the command I posted (as the second (working) one) doesn't have a `/` at the end of the remote path.

So:

```auto
me@me-desktop:~/TEMP/NR$ rsync -avz pi@192.168.0.93:/home/pi/TEMP/ /home/me/TEMP/NR/
receiving incremental file list
./
FF_Update2.txt
hosts

sent 65 bytes received 550 bytes 246.00 bytes/sec
total size is 661 speedup is 1.07
me@me-desktop:~/TEMP/NR$ 

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 September 2019 10:39 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/17 "2019-09-22T10:39:04Z")

</div>

> But I seem to remember it being pointed out that there is a `rsync` node for NR which _simplifies_ the use.

Touche. I digress 😉 didn't look at the actual node.

`rsync -avz ssh pi@192.168.0.93:/home/pi/.node-red home/me/TEMP/NR/`

should be; source - destination

`rsync -avz ssh /home/me/TEMP/NR/ pi@192.168.0.93:/home/pi/.node-red`

(note the absolute path `/home/zz` the first `/` is important.)

The example dceejay shows, is to get a file from a remote and store it locally (is that what you want ?)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 10:43 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/18 "2019-09-22T10:43:03Z")

</div>

No problems.

Putting aside the `node` now - though yes I brought it up:

What is with the ` ssh` in the command?

If I do it that way, it fails. I posted what I used and it works. That I can work out the _real_ command which works worries me. I'm **not** supposed to be that smart.

And

> [@bakman2](#):
>
> (note the absolute path `/home/zz` the first `/` is important.)

But this is what was given to me as working:  
`rsync -avz ssh pi@192.168.0.100:/home/pi/.node-red mylocalBackupDir1/`  
With no leading `/` on the local path.

I am not wanting to be rude @dceejay.

Just confused and wanting to get things clear.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 September 2019 10:46 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/19 "2019-09-22T10:46:57Z")

</div>

> [@bakman2](#):
>
> rsync -avz ssh /home/me/TEMP/NR/ [pi@192.168.0.93](mailto:pi@192.168.0.93):/home/pi/.node-red

Sorry. . . . .  
That is back to front.

I am on "machine A". I am copying to "machine A" from "machine B".

So shouldn't it be:  
`rsync -avz pi@192.168.0.93:/home/pi/.node-red/ /home/me/TEMP/NR/`  
source - destination.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 September 2019 10:49 UTC](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769/20 "2019-09-22T10:49:07Z")

</div>

> I am on "machine A". I am copying to "machine A" from "machine B".

~~I am confused. If you are on A than you are not copying from B.~~

let me think 😉

[Next page](https://discourse.nodered.org/t/trying-to-get-my-head-around-accessing-a-remote-directory-for-file-copying/15769.md?page=2)
