Best practices on how to erase everything in destination deployment folder and restart the app after deployment using Appveyor So far I have managed to get a simple deployment procedure running via SFTP. I really need to make two more steps:


Erase everything inside the folder that I am deploying to before I deploy a fresh build into it or (even better not sure this is possible) see what has changed and upload only the required and erase the not required. 
Restart the app after deployment is done.


What could be the best solution for this with Appveyor? So far I see the easiest way is to possibly include a power shell script that will connect via ssh and clear out the folder, not sure how that would work with restarting the app though. Would be really great to hear some more experienced users about this solution.
So it actually only took one line of code:

1) First take the SSH public key from the settings page inside the appveyor project and make sure you put it into the authorized_keys inside user_that_you_are_going_to_login_with_from_appveyor/.ssh/authorized_keys

2) To clear the folder before deploying to it on a Ubuntu server

before_deploy:    
  ssh user@host -t "rm -r -v /pathtofolder/*;exit; bash --login"


3) Now about the restart of the app I wanted to use after_deploy however there is a problem with that. After deploy fires straight after deploy and doesn't wait untill upload is finished. I wanted to use it to run 

systemctl restart myapp


However the problem seemed to solved itself because systemctl restarted my app at the moment when it was substituted with a new one or maybe at the moment when I call it the first time after the files have been reloaded. So far it seems I have a new app running after I run the script.