Hi!
I'm seeing some odd behaviour with regards to the CopyFileToGuest function. It seems a change was made in VirtualBox 5.1, that broke the support for copying a file to the guest in the following case:
[*] The destination is a file name, not a folder name.
[*] The destination file does not already exists in the Guest.
In this case the copy operation fails and the file isn't copied to the guest. If the destination is a directory rather than a file name, then the file is copied with no problems. The file is also overwritten successfully if it already exists.
Examples that fail:
[*] Source = "C:\filename.txt", Destination = "C:\filename.txt" - Unless a directory named "C:\filename.txt" exists in which case the file will be copied as "C:\filename.txt\filename.txt" in the guest, or unless the file already exists in the guest in which case it will be overwritten successfully.
I believe the error lies in https://www.virtualbox.org/browser/vbox ... s.cpp#L336 around line 336.
The code looks to attempt to see if the destination already exists, and if it is a file or a directory - but something goes wrong.
I think the problem is that if no directory or file with the output name exists, the rc variable is set to an error condition which then prevents the execution of vbox_cat on line 363.
Let me know if I should post this to the vbox_dev list instead, and if any more information would be useful
[Fixed] Issue with IGuestSession.CopyFileToGuest
-
- Posts: 22
- Joined: 11. Jun 2013, 08:35
- Primary OS: MS Windows 7
- VBox Version: PUEL
- Guest OSses: WinXP, WinVista, Win7, Win8
[Fixed] Issue with IGuestSession.CopyFileToGuest
Last edited by socratis on 4. May 2018, 21:07, edited 1 time in total.
Reason: Marked as [Fixed].
Reason: Marked as [Fixed].
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: Issue with IGuestSession.CopyFileToGuest
Could you give a piece of standalone code to reproduce the issue first please? And other listed points in the Posting Guidelines
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
-
- Posts: 22
- Joined: 11. Jun 2013, 08:35
- Primary OS: MS Windows 7
- VBox Version: PUEL
- Guest OSses: WinXP, WinVista, Win7, Win8
Re: Issue with IGuestSession.CopyFileToGuest
Yes, of course, sorry for not providing sufficient information!
VirtualBox version: 5.2.0
API: 5.2
MSCOM
C#
Windows 10 host, Windows 7 guest (although any Windows guest OS I've tried does the same)
Running the code results in an error code of -2135228411 if no file or directory with the name "C:\test.file" exists in the guest.
If "C:\test.file" exists as a directory, then the file is copied into the guest successfully as "C:\test.file\test.file".
If "C:\test.file" exists as a file, it is successfully overwritten.
VirtualBox version: 5.2.0
API: 5.2
MSCOM
C#
Windows 10 host, Windows 7 guest (although any Windows guest OS I've tried does the same)
Code: Select all
public static class VirtualBoxCopyTest
{
public static void Run()
{
VirtualBox.VirtualBox vb = new VirtualBoxClass();
IMachine machine = vb.FindMachine("machineName");
Session session = new Session();
machine.LockMachine(session, LockType.LockType_Shared);
while (session.State != SessionState.SessionState_Locked
&& machine.SessionState != SessionState.SessionState_Locked)
{
Thread.Sleep(0);
}
IGuestSession guestSession = session.Console.Guest.CreateSession("username", "password", "", "testSession");
GuestSessionWaitResult result = guestSession.WaitForArray(new GuestSessionWaitForFlag[] { GuestSessionWaitForFlag.GuestSessionWaitForFlag_Start }, 5000);
if (result == GuestSessionWaitResult.GuestSessionWaitResult_Start)
{
// guest session ready
IProgress copyProgress = guestSession.FileCopyToGuest(@"C:\path_to_host.file", @"C:\test.file", new FileCopyFlag[] { FileCopyFlag.FileCopyFlag_None });
copyProgress.WaitForCompletion(5000);
Console.WriteLine("Result: {0}", copyProgress.ResultCode);
}
guestSession.Close();
session.UnlockMachine();
}
}
If "C:\test.file" exists as a directory, then the file is copied into the guest successfully as "C:\test.file\test.file".
If "C:\test.file" exists as a file, it is successfully overwritten.
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: Issue with IGuestSession.CopyFileToGuest
Have you tried writting to another directly rather than the root of the C: drive? Root of drives are typically not writable with a regular account (or with UAC enabled). When you create the folder under C:\, you would effectively create a regular folder. And I'm guessing you are creating the folder with the same account as the one you're using in the API calls.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
-
- Posts: 22
- Joined: 11. Jun 2013, 08:35
- Primary OS: MS Windows 7
- VBox Version: PUEL
- Guest OSses: WinXP, WinVista, Win7, Win8
Re: Issue with IGuestSession.CopyFileToGuest
Yeah, the root directory was just for the test, usually I write to a subdirectory where all users have access.
I don't think it is an rights issue, as I am able to write to files using the IGuestSession.FileOpen and the IGuestFile interface in the same path as CopyFileToGuest fails to write to.
The user account I am using is an administrator in the guest, and UAC is disabled as well.
I don't think it is an rights issue, as I am able to write to files using the IGuestSession.FileOpen and the IGuestFile interface in the same path as CopyFileToGuest fails to write to.
The user account I am using is an administrator in the guest, and UAC is disabled as well.
-
- Site Moderator
- Posts: 5229
- Joined: 13. Jan 2012, 11:14
- Primary OS: Debian other
- VBox Version: OSE Debian
- Guest OSses: Debian, Win 2k8, Win 7
- Contact:
Re: Issue with IGuestSession.CopyFileToGuest
Fair enough. I'll try to replicate this on my end before moving this to the dev-list
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Manage your VirtualBox infrastructure the free way!
-
- Posts: 22
- Joined: 11. Jun 2013, 08:35
- Primary OS: MS Windows 7
- VBox Version: PUEL
- Guest OSses: WinXP, WinVista, Win7, Win8
Re: Issue with IGuestSession.CopyFileToGuest
I can confirm that VirtualBox 5.2.10 fixes this issue
-
- Site Moderator
- Posts: 27329
- Joined: 22. Oct 2010, 11:03
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Win(*>98), Linux*, OSX>10.5
- Location: Greece
Re: Issue with IGuestSession.CopyFileToGuest
Great, thanks for the feedback. Marking as [Fixed].
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.