Add support for directory upload to Upload()

Code refactoring. The Upload() function can handle both file
or directory (all files, recursively) upload.