Hi everyone!
I'm in a need of a shell script that search for all files in a folder, move all those files to a temp folder, and upload those files via FTP. When the file transfer via FTP completes successfully, the file is moved to a completed folder. In case any of those files fails, the file will be moved to a failed folder.
I have very little knowledge on Shell Scripting, but I'll try to explain as clear as possible what I need using a example flow below.
#!/bin/sh
# Configure variables at the begining of the script
MONITOR_DIR=/path/to/monitor/files/
TMP_DIR=/path/to/monitor/files/temp/
SUCCESS_DIR=/path/to/monitor/files/success/
FAILED_DIR=/path/to/monitor/files/failed/
PROCCESS_ID_DIR={execution timestamp string}
FILE_EXT=flv
# FTP variables
FTP_HOST=ftp.myserver.com
FTP_USER=mysername
FTP_PASS=mypassword
FTP_REMOTE_DIR=/
The script will work with these steps:
For each file with extension $FILE_EXT in $MONITOR_DIR
echo "found file: " and the name(s) of file(s) found
Move all found files to $TMP_DIR/$PROCCESS_ID_DIR (folder $PROCCESS_ID_DIR has to be created)
For each file in $TMP_DIR/$PROCCESS_ID_DIR
Upload via FTP each file individually using the FTP variables
If FTP transfer completes, move that file to $SUCCESS_DIR, else move it to $FAILED_DIR
echo "file (file_name) transfered" or "file (file_name) failed" depending on what happened above
When all the files in $TMP_DIR/$PROCCESS_ID_DIR are processed, delete $PROCCESS_ID_DIR folder in $TMP_DIR
quit script
That's basically it. I need this to monitor/backup/copy-to-CDN files uploaded to my site using a cron file.
Any help will be greatly appreciated...
Thanks!