VMware {code} Community
eatorres
Enthusiast
Enthusiast

Having trouble with CopyDatastoreFile_Task()...

I'm trying to use the CopyDatastoreFile_Tast() function, but I am having trouble getting the MOR to my datacenter. I'm using ESX 3.5 and the program I am writing is in C#, so what would be the best way to get an MOR to the datacenter so I can copy some files around. Also, does this function support copying files from a datastore into a guest OS? I've looked over the API reference and I can't seem to find a definite answer to this question. If so, how should I specify the destination file? Should it be something like "C:
folder
file.extension", assuming C:\ exists on the guest OS?

Reply
0 Kudos
5 Replies
Steve_Jin
Expert
Expert

The copyDataStoreFile_Task() does not support copying file into/out guest OS.

It might be possible with the VIX API, see Carter's blog: http://blogs.vmware.com/vix/

Steve JIN, VMware Engineering

Creator of VI Java API:

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
njain
Expert
Expert

There are couple of ways that you use to get the MOR to the datacenter.

1. You can use the "FindByInventoryPath" API method to get the reference. So, for e.g., if your datacenter name is "DC" and it exists directly under the root folder, you can get the MOR as:

> ManagedObjectReference datacenterRef = _service.FindByInventoryPath(searchIndex, "DC");

2. You can traverse the inventory and using the PropertyCollector managed object, you can get the reference to the datacenter from root. Please refer to the programming guide for more details on this approach.

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/visdk25programmingguide.pdf

eatorres
Enthusiast
Enthusiast

Both of your answers have been very helpful, however I still can't seem to be able to copy files around on my datastores. I feel as though I am missing a critical step somewhere (possibly getting the MOR to the FileManager that CopyDatastoreFile_Task() requires?). Is there any example code of copying a file from one folder on a datastore to another that someone could point me to? Thanks!

UPDATE: I guess my morning coffee finally kicked in and I was able to get it to work.

Reply
0 Kudos
amitstech
Contributor
Contributor

could you please share ur C# code for copy datastore?

Thanks-

Amit

Reply
0 Kudos
admin
Immortal
Immortal

Here's a sample that you can modify as per your need and utilize. It illustrates copydatastorefile_task api call.

Reply
0 Kudos