Wrong usage of dirname

According to documetation: dirname — Returns parent directory\'s path.
This means that after connecting the script landed to the wrong directoy.

This commnit fixes that and adds check to make sure paths add in slash /.

Signed-off-by: Baki Goxhaj <banago@gmail.com>