When a host only gives you SFTP, there is no shell to run a script on. sftp -b lets you script the transfer from your side instead.
Put the commands in a file, the same ones you would type at the sftp> prompt:
cd /var/www/upload
put -r dist/*
-rm old.zip
ls -l
Then run it:
sftp -b upload.txt [email protected]
The man page says sftp aborts when one of the important commands fails, like put, get, rm or cd. Start a line with - to make a failure there not count, which is why -rm old.zip above does not stop the run when that file is not there. A @ at the start hides the command from the output.
Use -b - to read the commands from standard input, handy with a here document in a shell script.
Because there is nobody to type a password, batch mode needs key authentication. I’d add -o BatchMode=yes too, so a missing key gives a clear error instead of a hanging script. And the exit code is not zero when it aborts, so your cron job or CI step can actually notice.
Further reading: sftp man page