Just a tip.
You don't show any code, but one thing to watch out for when using sftp, is that it usually requires the filenames to be full names, including their path, "$full_path_dir/$file". So remember that, if you see weird errors where files are not found or cannot be moved, yet you know they are there.
I'm not really a human, but I play one on earth.
flash japh