VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > c#教程 >
  • C#教程之C#教程之How to use the NFS Client c# Library

本站最新发布   C#从入门到精通
试听地址  
https://www.xin3721.com/eschool/CSharpxin3721/

类库下载

I add a wiki page that explains how to use the NFS Client c# .net library in your project.

NekoDrive uses a Library written in C# on .NET 2.0. that wraps the C++ NFS implementation. In order to use this library in your project download NekoDrive and copy in your project NekoDrive.NFS.dll, NFSv2.dll and NFSv3.dll. Add a reference in your project to NekoDrive.NFS.dll. Don't forget to include NFSv2.dll and NFSv3.dll as a content to deploy.

you download this library here:

http://code.google.com/p/nekodrive/

EXAMPLE 1 - CONNECT TO NFS SERVER AND GET THE EXPORTED DEVICES

复制代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using NekoDrive.NFS;
using NekoDrive.NFS.Wrappers;


namespace Example1
{
   class Program
    {
        static void Main(string[] args)
        {
            using(NFS nfs = new NFS(NFS.NFSVersion.v2))
            {
                if (nfs.Connect(IPAddress.Parse("161.55.201.250")) == NFSResult.NFS_SUCCESS)
                {
                    foreach(string device in nfs.GetExportedDevices())
                        Console.WriteLine(device);
                    nfs.Disconnect();
                }
            }
        }
    }
}
复制代码

EXAMPLE 2 - CONNECT TO NFS SERVER, MOUNT THE FIRST EXPORTED DEVICE AND GET THE FILE LIST

复制代码
namespace Example2
{
    class Program
    {
        static void Main(string[] args)
        {
            using(NFS nfs = new NFS(NFS.NFSVersion.v2))
            {
                if (nfs.Connect(IPAddress.Parse("161.55.201.250")) == NFSResult.NFS_SUCCESS)
                {
                    List devices = nfs.GetExportedDevices();
                    if(devices.Count > 0)
                    {
                        if(nfs.MountDevice(devices[0]) == NFSResult.NFS_SUCCESS)
                        {
                            foreach(string item in nfs.GetItemList())
                            {
                                NFSAttributes attrib = nfs.GetItemAttributes(item);
                                Console.WriteLine(item + " " + attrib.cdateTime.ToString() + " " + attrib.size);
                            }
                            nfs.UnMountDevice();
                        }
                    }
                    nfs.Disconnect();
                }
            }
        }
    }
}
复制代码

EXAMPLE 3 - CONNECT TO NFS SERVER, MOUNT THE FIRST EXPORTED DEVICE AND DOWNLOAD A FILE IN THE ROOT FOLDER (.)

复制代码
namespace Example3
{
    class Program
    {
        static void Main(string[] args)
        {
            using(NFS nfs = new NFS(NFS.NFSVersion.v2))
            {
                if (nfs.Connect(IPAddress.Parse("161.55.201.250")) == NFSResult.NFS_SUCCESS)
                {
                    List devices = nfs.GetExportedDevices();
                    if(devices.Count > 0)
                    {
                        if(nfs.MountDevice(devices[0]) == NFSResult.NFS_SUCCESS)
                        {
                            if(nfs.Read("test.txt", ".", @"c:\test.txt") != NFSResult.NFS_SUCCESS)
                                Console.WriteLine(nfs.GetLastError());
                            nfs.UnMountDevice();
                        }
                    }
                    nfs.Disconnect();
                }
            }
        }
    }
}
复制代码

EXAMPLE 4 - CONNECT TO NFS SERVER, MOUNT THE FIRST EXPORTED DEVICE AND UPLOAD A FILE IN THE "TEST/SUB" SUBFOLDER

复制代码
namespace Example4
{
    class Program
    {
        static void Main(string[] args)
        {
            using(NFS nfs = new NFS(NFS.NFSVersion.v2))
            {
                if (nfs.Connect(IPAddress.Parse("161.55.201.250")) == NFSResult.NFS_SUCCESS)
                {
                    List devices = nfs.GetExportedDevices();
                    if(devices.Count > 0)
                    {
                        if(nfs.MountDevice(devices[0]) == NFSResult.NFS_SUCCESS)
                        {
                            if(nfs.Write("test.txt", "test/sub", @"c:\test.txt") != NFSResult.NFS_SUCCESS)
                                Console.WriteLine(nfs.GetLastError());
                            nfs.UnMountDevice();
                        }
                    }
                    nfs.Disconnect();
                }
            }
        }
    }
}
复制代码
版权声明:本博客所有图片、文字等版权属于虫子樱桃所有,未经许可谢绝任何形式的复制和传播。博客的图片和代码部分来自网络,本站均已注明来源和作者原来的声明。如有侵权,请使用本站联系方式告诉,我们将会在第一时间做出处理。
相关教程