I have linux client and linux server. Both are Ubuntu 16.04.
On the client I generated .txt files almost every second, and I want to transfer them to the server, so my question is: what is the best solution for this purpose?

I did this script:



while true
    for entry in "$path"/*.txt
            if [ -f "$entry" ]
                scp "$entry" [email protected]:/home/4lkov/Desktop/scp && rm -f "$entry"
                echo "No files";
    sleep 1

So, I'm using SCP is it reliable or is there best ways (rsync or similar)?
Also I'm using sleep 1.. probably there is some watchdog? (i.e inotifywait -m /path -e create -e moved_to | )

  • 1
    You already have the right answer - inotifywait on the directory will do the job.
    – l0b0
    Apr 26, 2018 at 7:27
  • Yes, what's about scp?
    – Nik Konst
    Apr 26, 2018 at 7:57
  • 1
    scp is fine, rsync is more appropriate when you have many files (which you won't have unless you make the inotifywait code more complex by accumulating filenames for a while between transfers). rsync does have an option to remove the source file on completion of the transfer, though, if that is needed.
    – l0b0
    Apr 26, 2018 at 8:09
  • Mount the remote machine using sshfs and just create the files on the remote machine to start with?
    – ivanivan
    Apr 26, 2018 at 12:59
  • I would probably use something like Syncthing for this, or mount the directory as a NFS share.
    – Kusalananda
    Apr 27, 2018 at 8:53

1 Answer 1


This script loops forever over every file in $path and opens a SCP connection to transfer each file individually, pausing every second. This has a high overhead. Better use rsync instead to synchronize the directory from server to client.

  • Well, rsync do the same, isn't? (I mean opens connection) rsync -avz *.txt root@<remote-ip>:/home/test *I need to remove file after it was sent.
    – Nik Konst
    Apr 26, 2018 at 7:55
  • Using a tool made for the job (rsync in this case) is better than reinventing the wheel.
    – dr_
    Apr 26, 2018 at 7:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .