FTP upload all recently modified files

I’ve been doing some development on a WordPress site recently. Due to limitations of the hosting environment, deploying from git is not an option – I have had to FTP the changed files to the staging server to test my changes. Since I don’t know PHP I am redeploying files repeatedly with minor fixes. To streamline my uploads I wrote this small bash script (to run in my Ubuntu WSL running on Windows 10) to upload all files modified within a supplied number of minutes.

[code language=”bash”]
#!/bin/bash
HOST=ftp.host.com
USER=username@host.com
PASS=veryInsecurePassword

(
echo user $USER $PASS
echo passive
find ./wp-content/plugins/myplugin/ -mmin -$1 -not -path "*/js/*" -not -path "*/js" | while read line; do
echo "put $line"
done
echo quit
) | ftp -inv $HOST
[/code]

The magic is done in the find command. I supply the number of minutes as a parameter and this will find all files modified since that time and upload them. I exclude the js folder because it contains my source files – I have an npm script to move compiled/minified js to their forever location in my WordPress plugin.

I am going to add some clever use of environmental variables to store the time of each upload and upload all changed files since then – should fix any off-by-a-minute issues that I just know will happen.