I'm having difficulty downloading file from VM using 'InitiateFileTransferFromGuest' in python. Here's the code:
def main8(host,user,password,
VM_NAME,VM_USER,VM_PASS,LOCAL_FILE_PATH,REMOTE_FILE_PATH,UUID):
class Namespace:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
args = Namespace(host=host,user=user,password=password,
disable_ssl_verification=True,port=443,
find = None,REMOTE_FILE_PATH=REMOTE_FILE_PATH,
VM_NAME=VM_NAME,VM_USER=VM_USER,VM_PASS=VM_PASS,
LOCAL_FILE_PATH=LOCAL_FILE_PATH,UUID=UUID)
vm_path = args.REMOTE_FILE_PATH
try:
si = service_instance.connect(args)
content = si.RetrieveContent()
vm = None
if args.UUID:
search_index = si.content.searchIndex
vm = search_index.FindByUuid(None, args.UUID, True)
elif args.VM_NAME:
content = si.RetrieveContent()
vm = pchelper.get_obj(content, [vim.VirtualMachine], args.VM_NAME)
if not vm:
raise SystemExit("Unable to locate VirtualMachine.")
print("Found: {0}".format(vm.name))
tools_status = vm.guest.toolsStatus
if (tools_status == 'toolsNotInstalled' or
tools_status == 'toolsNotRunning'):
raise SystemExit(
"VMwareTools is either not running or not installed. "
"Rerun the script after verifying that VMWareTools "
"is running")
creds = vim.vm.guest.NamePasswordAuthentication(username=args.VM_USER, password=args.VM_PASS)
try:
src="C:\\remote\\1.txt" #Server's directory
fti = content.guestOperationsManager.fileManager.InitiateFileTransferFromGuest(vm, creds, src)
print(fti.url)
dest="C:\\local\\1.txt"
resp=requests.get(fti.url, verify=False)
with open(dest, 'wb') as f:
f.write(resp.content)
except IOError as ex:
print('error :::',ex)
except vmodl.MethodFault as error:
print("Caught vmodl fault :::: " + error.msg)
the log output is as the following:
vm:::::::::output--Found: Win10 X64 4*4*50
"error ::: URL has an invalid label."
thanks for helping