Showing posts with label rsync. Show all posts
Showing posts with label rsync. Show all posts

Thursday, November 5, 2020

Using rsync without ssh

Recently I have encountered a situation whereby I need to transfer a file to a server, and ssh client and server are not installed in that server. And to make matters worst, that server does not have internet connection for me to install openssh-clients on it. Luckily, that server has rsync installed, which kind of save my day. 


What I will show here, is how to transfer file using rsync protocol without ssh. We will call the server without ssh, and without internet connectivity with serverA, and the other server that has internet connectivity as serverB.

serverA: server without ssh and internet connectivity

serverB: server with internet connectivity


After I have acquired all the files needed by serverA by downloading in serverB, I need to start rsync in daemon mode. Before that, I need to tell rsync which folder that I wish to share via the rsync protocol, by editing /etc/rsyncd.conf. Let's say I want to share my /tmp directory, which contain a file called myfile.txt.

serverB # cat >> /etc/rsyncd.conf <<EOF

[tmp]

    path = /tmp

EOF


Next, start rsync in daemon mode. Rsync will make use of the /etc/rsyncd.conf for the daemon configuration.

serverB # rsync --daemon


We can see that rsync by default will listen on port 873

serverB # ss -tulpn | grep rsync

tcp     LISTEN   0        128              0.0.0.0:873             0.0.0.0:* 


In serverA, we need to use the rsync command to connect to rsync daemon in serverB. To check which directory is available for download:

serverA # rsync serverB::

tmp


Download the file

serverA # rsync serverB::tmp/myfile.txt

serverA # ls 

myfile.txt


You have now downloaded the myfile.txt file, from serverB just by using rsync. A note to remember, rsync protocol does not have any encryption, but it is good enough for a LAN environment.

Tuesday, January 9, 2018

Rsync to a different ssh port

In order to use rsync with different ssh post, you can use -e flag, and supply ssh command with port option. For example, I want to transfer a file called /root/book.txt from a server called project.local with sshd running on port 55522 to local partition /mnt, I can use this command:

$ rsync -avz --progress -e "ssh -p 55522" root@project.local:/root/book.txt /mnt

where:
-a for archive mode
-v for verbose
-z to compress data during transfer
--progress for showing progress of the copy
-e to specify the remote shell to use, in this case to use ssh to port 55522

Tuesday, January 5, 2010

Continue stalled scp file transfer session

Stalled scp file transfer session will happen when the network connection is unstable. You can see the status of the session at the message shown at your stdout like below:

file1 3% 136MB 0.0KB/s - stalled -


To continue back the file transfer, you can use this command at a new terminal, but make sure both the server and client have rsync installed:

$ rsync --partial --progress --rsh=ssh username@server:/path/to/remote-file /path/to/local-file

For example, if the transfer of file1 is stalled for user abu:

$ rsync --partial --progress --rsh=ssh abu@master:/home/abu/file1 /home/abu/file1

The scp transfer process will continue transferring the file

file1 4% 136MB 300.0KB/s 2:03:17 ETA