VirtualBox:使用python在virtualBox中将文件从主机复制到来宾

时间:2018-10-29 06:58:13

标签: python-3.x virtualbox

我正在尝试使用VirtualBox python SDK将文件从Windows 10主机复制到Ubuntu来宾。

import vboxapi
SOURCE_PATH = r"K:\Downloads\first.sh"
DEST_PATH = r"/home/myuser/Downloads/first.sh"
UNAME = "myuser"
PASSWD = "mypass"
MACH_NAME = "Test"
virtualBoxManager = vboxapi.VirtualBoxManager(None, None)
vbox = virtualBoxManager.getVirtualBox()
todo = vbox.findMachine(MACH_NAME)
session = virtualBoxManager.getSessionObject(vbox)
progress = todo.launchVMProcess(session, "headless", None)
progress.waitForCompletion(-1)
console = session.console
runner = console.guest.createSession(UNAME, PASSWD, "", "")
print(runner.waitFor(virtualBoxManager.constants.GuestSessionWaitForFlag_Start, 0))
copy = runner.fileCopyToGuest(SOURCE_PATH, DEST_PATH, None)
copy.waitForCompletion(-1)
print(runner.fileExists(DEST_PATH, False))
console.powerDown()
# session.unlockMachine()
# virtualBoxManager.closeMachineSession(session)

但是,不会复制文件。另外,尝试检查文件是否存在时会引发以下错误。

  

回溯(最近通话最近):     在第18行的文件“ K:\ WorkSpace \ GOC \ VBinit.py”中       打印(runner.fileExists(DEST_PATH,False))     FileExists中的文件“ C:\ Users \ kaust \ AppData \ Local \ Temp \ gen_py \ 3.7 \ D7569351-1750-46F0-936E-BD127D5BC264x0x1x3.py”,行3902       ,aFollowSymlinks)   pywintypes.com_error:(-2147352567,“发生异常。”,(0,“ GuestSessionWrap”,“为“ /home/myuser/Downloads/first.sh”查询文件信息”失败:VERR_BROKEN_PIPE',无,0,-2135228411) ,无)

为什么它不起作用,我应该进行哪些更改以使其起作用?

0 个答案:

没有答案