sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

`file_copy_to_guest()` Failed without any error messages #98

Closed wahtherewahhere closed 6 years ago

wahtherewahhere commented 7 years ago
SUMMARY

file_copy_to_guest does not work file_copy_from_guest does. Code goes failed without ERROR.

STEPS TO REPRODUCE
   vm = vbox.find_machine("a-ubuntu-distro")
   session = vm.create_session()
   guest = session.console.guest.create_session("root","some-password")
   progress = guest.file_copy_to_guest("D:\\test2", "/tmp/test2", [virtualbox.library.FileCopyFlag.none])
   progress.wait_for_completion()
EXPECTED RESULTS

ls /tmp in VM and see the file.

ACTUAL RESULTS

progress.wait_for_completion() returns, but there are no file in /tmp

sethmlarson commented 7 years ago

Did you check the error status of the progress object? See progress.result_code and progress.error_info.

wahtherewahhere commented 7 years ago

There are two kind of error messages. If the code is guest.file_copy_to_guest("D:\\test.txt", "/root/test2", [virtualbox.library.FileCopyFlag.none]) The error message is "The specified file was not found on guest" (result_code: -2135228411)

Another one is guest.file_copy_to_guest("/root/test2", "D:\\test.txt", [virtualbox.library.FileCopyFlag.none]). (I guess maybe the vbox api put the wrong parameters location so I change the sort.) The error message is empty (result_code: 0).

sethmlarson commented 7 years ago

Can you try using: guest.file_copy_to_guest('D:\\test.txt', '/root/test2', [virtualbox.library.FileCopyFlag.update]). Seems the update flag also allows a file to be created if it doesn't exist on the guest.

Source:

"""
    .. describe:: update(4)
            Only copy when the source file is newer than the destination file
            or when the destination file is missing.
            This flag is not implemented yet. 
"""

If this flag actually isn't implemented then you should try creating an empty file on the guest first before using copy? I'm just inferring that from the error message. The first parameter order is definitely the right one.

sethmlarson commented 7 years ago

This would be nice as a helper function, I should look into fixing these up in library_ext in 2.0.0.

wahtherewahhere commented 7 years ago

I organize the results in the following table. The flag update is not the solution. Only the first configuration works. A helper function is a good idea for wrapping this staffs :clinking_glasses: (cheers)

Create ? Overwrite if exists? Source Target Flag Result Code Error Message
:+1: :+1: D:\test.txt /root/ [FileCopyFlag.none] 0 (n/a)
:x: :x: D:\test.txt /root/test.txt [FileCopyFlag.none] -2135228411 The specified file was not found on guest
:x: :x: D:\test.txt /root/ [FileCopyFlag.update] -2135228411 Copy flags (0x4) not implemented yet
:x: :x: D:\test.txt /root/test.txt [FileCopyFlag.update] -2135228411 Copy flags (0x4) not implemented yet
sethmlarson commented 7 years ago

Thanks for all these results! We definitely need to add a nice helper for this function because it doesn't behave like a typical copy.

sethmlarson commented 6 years ago

I'm glad we got to the bottom of this. I'm going to close this as complete, if you would like to add the helper to the project please do so against 2.0.0 branch. Thanks!

sk3lk0 commented 4 years ago

hi, im trying copy file from my machine to VM via using this code:

progress = guest_sesson.file_copy_to_guest("/home/user/Desktop/1.txt", "C:\\", [virtualbox.library.FileCopyFlag.none])
progress.wait_for_completion()

but progress.result_code is -2135228411 Are you have any ideas?

FXTi commented 4 years ago

hi, im trying copy file from my machine to VM via using this code:

progress = guest_sesson.file_copy_to_guest("/home/user/Desktop/1.txt", "C:\\", [virtualbox.library.FileCopyFlag.none])
progress.wait_for_completion()

but progress.result_code is -2135228411 Are you have any ideas?

Yes, I have the same issue:

>>> progress = gs.file_copy_to_guest("/mnt/VM/python-3.7.6-amd64.exe","C:\test",[virtualbox.library.FileCopyFlag.none])
>>> progress.wait_for_completion()
>>> progress.error_info.text
'Destination file lookup for "C:\test" failed: VERR_GENERAL_FAILURE'
malpwn commented 4 years ago

Same issue as above can we please get this handled ?

sethmlarson commented 4 years ago

I don't have a lot of time to devote to this project. If you can do more investigation or provide a PR I'm willing to review.

malpwn commented 4 years ago

Here's the actual scenario workers_api_1 | VBoxManage: error: File copy failed workers_api_1 | VBoxManage: error: Querying information on for '"C:\Users\test\Desktop\putty.exe"' failed: VERR_INTERNAL_ERROR_5 workers_api_1 | VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestSessionWrap, interface IGuestSession workers_api_1 | VBoxManage: error: Context: "RTEXITCODE gctlHandleCopy(PGCTLCMDCTX, int, char**, bool)" at line 1940 of file VBoxManageGuestCtrl.cpp workers_api_1 | VBoxManage: error: Querying information on for '"C:\Users\test\Desktop\putty.exe"' failed: VERR_INTERNAL_ERROR_5.