diff --git a/src/client/cmdVM/vmImportDir.go b/src/client/cmdVM/vmImportDir.go
index 60e3fe861814d537c563476e0c3472a33311e153..03cb894e34c99d51348a94d0020a24d2ec542275 100644
--- a/src/client/cmdVM/vmImportDir.go
+++ b/src/client/cmdVM/vmImportDir.go
@@ -2,7 +2,6 @@ package cmdVM
 
 import (
 	u "nexus-client/utils"
-	g "nexus-libclient/globals"
 	libclient "nexus-libclient/vm"
 
 	"os"
@@ -38,9 +37,6 @@ IMPORTANT: to avoid disk corruption, files can only be imported into non-running
 }
 
 func (cmd *ImportDir) Run(args []string) int {
-	client := g.GetInstance().Client
-	host := g.GetInstance().Host
-
 	argc := len(args)
 	if argc < 3 {
 		cmd.PrintUsage()
@@ -76,21 +72,12 @@ func (cmd *ImportDir) Run(args []string) int {
 	}
 
 	for _, vm := range vms {
-		uuid := vm.ID.String()
-		resp, err := client.R().SetFile("file", tmpTarGzFile).
-			SetFormData(map[string]string{
-				"vmDir": vmDir,
-			}).Post(host + "/vms/" + uuid + "/importfiles")
+		err := libclient.VMImportArchive(vm.ID.String(), vmDir, tmpTarGzFile)
 		if err != nil {
 			u.PrintlnErr("Failed copying \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\": " + err.Error())
 			statusCode = 1
 		} else {
-			if resp.IsSuccess() {
-				u.Println("Copied \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\"")
-			} else {
-				u.PrintlnErr("Failed copying \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\": " + resp.Status() + ": " + resp.String())
-				statusCode = 1
-			}
+			u.Println("Copied \"" + localDir + "\" into \"" + vmDir + "\" in VM \"" + vm.Name + "\"")
 		}
 	}
 
diff --git a/src/libclient/vm/vmImportArchive.go b/src/libclient/vm/vmImportArchive.go
new file mode 100644
index 0000000000000000000000000000000000000000..47e93eec5d5b1a8ab6e223169e223db72fba5b36
--- /dev/null
+++ b/src/libclient/vm/vmImportArchive.go
@@ -0,0 +1,25 @@
+package vm
+
+import (
+	g "nexus-libclient/globals"
+	"nexus-libclient/response"
+)
+
+func VMImportArchive(vmID, vmDir, archiveFile string) error {
+	client := g.GetInstance().Client
+	host := g.GetInstance().Host
+
+	resp, err := client.R().SetFile("file", archiveFile).
+		SetFormData(map[string]string{
+			"vmDir": vmDir,
+		}).Post(host + "/vms/" + vmID + "/importfiles")
+
+	if err != nil {
+		return err
+	}
+	if resp.IsSuccess() {
+		return nil
+	} else {
+		return response.ErrorToMsg(resp)
+	}
+}