Skip to content

Automatically Transfer Files via SSH

Problem

I have files that I load from my dash camera and phone. I have an application that will assemble those files into a tarball that would then be processed into a video to post online.

Solution

To improve the efficiency of completing that process, I decided to create a script that would do this for me. The way that the script works is that it will transfer all of the tarballs that are in the directory to the media server. The media server is where the script runs to create the videos that are ready for uploading.

Once the files have been uploaded, they are then moved to a different folder on the computer to prevent them from being reuploaded again. If a file transfer where to fail, for example if the server were rebooted during transfer, then the file would be re-transferred again when the system comes back online.

The sript is call via a cronjob multiple times per day. The script works even when there are no files present that meet the transfer criteria.

The Script

#!/bin/bash 

###############################################
# Author: Kenny Robinson, @almostengr
# DESCRIPTION: This script transfers files to the main computer 
# to the rendering server for processing
###############################################

/bin/date

/bin/echo "Transferring files"

/usr/bin/scp -p /home/almostengineer/Videos/dashcamvideos/*tar.gz iamadmin@media://mnt/ramfiles/dashcam/incoming

/usr/bin/scp -p /home/almostengineer/Videos/aevideos/*tar.gz iamadmin@media://mnt/ramfiles/almostengineer/incoming

/bin/date 

/bin/echo "Moving files to archive"

mv /home/almostengineer/Videos/dashcamvideos/*tar.gz /mnt/d74511ce-4722-471d-8d27-05013fd521b3/Kenny\ Ram\ Dash\ Cam/archive

mv /home/almostengineer/Videos/aevideos/*tar.gz /mnt/d74511ce-4722-471d-8d27-05013fd521b3/Almost\ Engineer/archive

/bin/echo "Process complete"

/bin/date

Last update: 2021-06-17 Last update: Kenny Robinson
ssh, sftp, file transfer, scp, linux, secure file transfer