Few code optimizations

Just a few optimizations: removed a repeated if() with the same clause, throwed an exception when unable to connect to a server and refactored the removal of $files_to_ignore with $files_to_upload with a one-liner array_diff().