 +{
 +    ARCHIVE=$1
 +    OUTPUT=$2
++    HOST=$3
 +
 +    if [ $(file_ends_with $ARCHIVE '.tar.gz') = 0 ]; then
-+        $FORMAT=z
++        FORMAT=z
 +    elif [ $(file_ends_with $ARCHIVE '.tar.bz2') = 0 ]; then
-+        $FORMAT=j
++        FORMAT=j
 +    elif [ $(file_ends_with $ARCHIVE '.tar.xz') = 0 ]; then
-+        $FORMAT=J
++        FORMAT=J
++    fi
++    
++    TAR_CMD="tar -x${FORMAT}f $ARCHIVE"
++
++    if [ "x$HOST" != "x" ]; then
++       SSH_CMD="ssh $HOST"
 +    fi
 +
-+    TAR_CMD="tar -x${FORMAT}f $ARCHIVE"
-+
 +    if [ "x$OUTPUT" != "x" ]; then
-+        $TAR_CMD -O > $OUTPUT
++        if [ "x$HOST" != "x" ]; then
++            $SSH_CMD "$TAR_CMD -O > $OUTPUT"
++        else
++            $TAR_CMD -O > $OUTPUT
++        fi
 +    else
-+        $TAR_CMD
++        $SSH_CMD $TAR_CMD 
 +    fi
 +}
 +

+    HOST=$4
+
+    if [ "x$HOST" != "x" ]; then
+        HOST="ssh $HOST"
+    fi
+
+    $HOST curl -k -o $ARCHIVE $URL
+
+    extract_tar $ARCHIVE $FILENAME
+
+    rm -rf $ARCHIVE
+}
+
+function file_ends_with

diff --git a/src/tm_mad/tm_common.sh b/src/tm_mad/tm_common.sh
index 0f589fe..dcd03cb 100644
--- a/src/tm_mad/tm_common.sh
+++ b/src/tm_mad/tm_common.sh
@@ -145,3 +145,65 @@ function timeout_exec_and_log
         exit $CMD_CODE
     fi
 }
+
+function download_extract
+{
+    URL=$1
