def copyRandomFile(fileNames, destination):
# Select a random file
fileNameWithPath = fileNames[randint(0, len(fileNames)-1)]
if platform.system() == "Linux":
separator = "/"
elif platform.system() == "Windows":
separator = "\\"
# If the file is copied to the VM, the MAC address (as an integer) is placed before the file names
# -> Avoid deadlocks when copying to the server
if "localstorage" in destination:
localFileName = str(getnode()) + "-" + fileNameWithPath.split(separator)[-1]
else:
localFileName = fileNameWithPath.split(separator)[-1]
# Path to the corresponding drive and filename
dstWithFileName = destination + localFileName
# Copy file
try:
copyfile(fileNameWithPath, dstWithFileName)
echoC(__name__, "Copied file " + localFileName + " to " + destination)
except Exception as e:
echoC(__name__, "copyfile() with destination " + destination + " error: " + str(e))
return -1
# copyfile() is not blocking
time.sleep(random.randint(15, 300))
return 0
# Select a file and copy it to the VM or the file server
评论列表
文章目录