diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 18aa53a892b0d12164dc6d1f9b7ed26144b95b42..befbc38117a81bbe2fa20b2f029cb7693c73b8f7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,6 +3,8 @@ before_script:
   - ./configure.sh
 
 upload:
+  only:
+    - master
   script:
     - ./upload
 
diff --git a/index.js b/index.js
index bd93f3970ca8ca0a6c8636f67454e038b8c2cd60..97ca44b1d0f323b0e68e5488a5a9e6ada3b5f5e3 100755
--- a/index.js
+++ b/index.js
@@ -51,6 +51,7 @@ var sitegin = function(config) {
       .catch(function(e) {
         isRunning = false;
         console.log('Generator crashed in',moment().diff(startTime,'seconds'),'seconds')
+        if(config.options.noserver) process.exit(13);
         if(runAgain) run();
         if(e.stack)
           console.log(e.stack)
diff --git a/upload b/upload
index f7ea1bf143b10981ce348142fdd85c840c6313e5..3f62eef6a4c258acc4d7b1b90ca4302dba46b1d1 100755
--- a/upload
+++ b/upload
@@ -8,7 +8,12 @@ fi
 rm -rf build
 mkdir -p build/theme
 time node index.js --noserver
-echo "Site compiled"
+echo "Site compilation ended with status code $?"
+if [ $? -ne 0 ]
+then
+    echo "Error detected. Exitting."
+    exit 1
+fi
 chmod a+X build -R
 
 USER=ok1kvk.cz-www-nove
@@ -17,22 +22,29 @@ MAX_RETRIES=2
 RECONNECT_INTERVAL=5
 
 echo "======================================================================"
-echo "Uploading to nove.ok1kvk.cz"
+echo "Uploading to $HOST"
 if [ "$1" == "ftp" ]; then
     echo "Using FTP"
-    time lftp -c "set cmd:fail-exit yes;\
+    time lftp -e "set cmd:fail-exit yes;\
                   set net:timeout 5;\
                   set net:reconnect-interval-base $RECONNECT_INTERVAL;\
                   set net:max-retries $MAX_RETRIES;\
                   set ftp:ssl-allow no;\
                   open --user $USER --env-password ftp://$HOST/;\
-                  mirror -c --verbose=9 -e -R -L ./build /"
+                  mirror -c --verbose=9 -e -R -L ./build /;\
+                  exit 0;"
+    echo "LFTP finished with return code $?"
 else
     echo "Using SFTP"
-    time lftp -c "set cmd:fail-exit yes;\
+    time lftp -e "set sftp:auto-confirm yes;\
+                  set cmd:fail-exit yes;\
                   set net:timeout 5;\
                   set net:reconnect-interval-base $RECONNECT_INTERVAL;\
                   set net:max-retries $MAX_RETRIES;\
                   open --user $USER --env-password -p 2121 sftp://$HOST/;\
-                  mirror -c --verbose=9 -e -R -L ./build /"
+                  mirror -c --verbose=9 -e -R -L ./build /;\
+                  exit 0;"
+    echo "LFTP finished with return code $?"
 fi
+exit 0
+