 
 putDirectory = (devicename, directoryPath, recursive, callback) ->
     # Fix callback
-    if not callback?
-        callback = () ->
+    if not callback? or typeof callback is 'object'
+        callback = (err) ->
+            process.exit 1 if err?
+            process.exit 0
 
     # Get config
     remoteConfig = config.config.remotes[devicename]
 
     # Get dir name
     dirName = path.basename directoryPath
+    if dirName is '.'
+        return callback()
 
     # Find directory's parent directory
     absolutePath = path.resolve directoryPath
     relativePath = absolutePath.replace remoteConfig.path, ''
     if relativePath is absolutePath
         log.error "Directory is not located on the synchronized directory: #{dirPath}"
-        callback
+        return callback()
     if relativePath.split('/').length > 2
         dirPath = relativePath.replace "/#{dirName}", ''
     else

    putDirectory devicename, ".#{filePath}", false, (err, res) ->

        # Fetch only files with the same path/filename
        db.db.query { map: (doc) -> emit doc._id, doc if doc.docType is 'File' }, (err, res) ->
            for doc in res.rows
                doc = doc.value
                if doc.name is fileName and doc.path is filePath


fetchBinaries = (devicename, options, callback) ->
    # Fix callback
    if not callback? or typeof callback is 'object'
        callback = (err) ->
            process.exit 1 if err?
            process.exit 0

    # Get config
    remoteConfig = config.config.remotes[devicename]
