The following sample shows how to get a list of files and directories from the Hardware Node. The path
parameter is used to specify the directory (or multiple directories) for which to get the list of files and subdirectories.
/// <summary>
/// Sample function ListHNfiles.
/// Lists files and directories on a Hardware Node.
/// </summary>
/// <param name="path">Pathname(s).</param>
/// <returns>A string containing the list of files.</returns>
///
public string ListHNfiles(string[] path)
{
try {
string list_result = "";
// Instantiate the proxy class.
filerBinding filer = (filerBinding)binder.InitBinding(typeof(filerBinding));
// The main input object.
list2 list = new list2();
// Set pathnames.
byte[][] paths = new byte[path.Length][];
for (int i = 0; i < path.Length; i++) {
paths[i] = System.Text.ASCIIEncoding.ASCII.GetBytes(path[i]);
}
list.path = paths;
/* Get file listing, then iterate through it and
* populate a string variable with the results.
*/
foreach (fileType file in filer.list(list)) {
list_result += "\n\nName: " + System.Text.ASCIIEncoding.ASCII.GetString(file.name) +
"\nSize: " + file.size.ToString() + "\nType: " + file.type.ToString();
}
return list_result;
}
catch (Exception e) {
return "Exception: " + e.Message;
}
}
The following sample functions shows how to get a list of files and directories from a Virtuozzo Container. Note that the only difference between this function and the sample function above is how we create the proxy class object. Here, we use the overloaded binder.InitBinding
method that has the additional eid
parameter, which we use to specify the target Virtuozzo Container. As a result, the request will be routed to the specified Container and the file listing will be obtained from the Container instead of the Hardware Node.
/// <summary>
/// Sample function ListCTfiles.
/// Lists files and directories on a Container.
/// </summary>
/// <param name="path">Pathname(s).</param>
/// <param name="eid">
/// Server ID of the Container.
/// </param>
/// <returns>A string containing the list of files.</returns>
///
public string ListCTfiles(string[] path, string eid)
{
try {
string list_result = "";
// Instantiate the proxy class.
filerBinding filer = (filerBinding)binder.InitBinding(typeof(filerBinding), eid);
// The main input object.
list2 list = new list2();
// Set pathnames.
byte[][] paths = new byte[path.Length][];
for (int i = 0; i < path.Length; i++) {
paths[i] = System.Text.ASCIIEncoding.ASCII.GetBytes(path[i]);
}
list.path = paths;
/* Get file listing, then iterate through it and
* populate a string variable with the results.
*/
foreach (fileType file in filer.list(list)) {
list_result += "\n\nName: " + System.Text.ASCIIEncoding.ASCII.GetString(file.name) +
"\nSize: " + file.size.ToString() + "\nType: " + file.type.ToString();
}
return list_result;
}
catch (Exception e) {
return "Exception: " + e.Message;
}
}