Hi all,
i need to upload a file (e.g. my test.vmdk file) to my datastore.
the download of a file works perfect, but when start a upload the debugger says that everything is fine and there's no file uploaded to my directory.
i want to upload a file via this path http://myvm:8222/folder/WinXP/test.vmdk?dcPath=mydatacenter&dsName=mydatastore
to upload a file, i use this c# code:
public void Upload( )
{
FileStream reader = new FileStream(@"C:\test\test.vmdk", FileMode.Open);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://myvm:8222/folder/WinXP/test.vmdk?dcPath=mydatacenter&dsName=mydatastore");
req.Method = "PUT";
req.PreAuthenticate = true;
req.Timeout = 5000;
req.KeepAlive = true;
req.UserAgent = "test upload";
req.ContentLength = reader.Length;
req.Credentials = new NetworkCredential(username, password);
Stream stream = null;
try
{
stream = req.GetRequestStream();
if (stream != null)
{
// Read
byte[] buffer = new byte[http://reader.Length|http://reader.Length];
int bytesRead = reader.Read(buffer, 0, (int)reader.Length);
if (bytesRead > 0)
{
stream.Write(buffer, 0, bytesRead);
}
reader.Close();
reader.Dispose();
}
stream.Flush();
stream.Close();
stream.Dispose();
}
catch { }
}
has anybody an idea?
bye
mavu0011