.NET Core(C#)支持跨平台开发吗?
- 内容介绍
- 文章标签
- 相关推荐
本文共计238个文字,预计阅读时间需要1分钟。
在.NET Core中,使用SharpCifs库访问Windows共享目录或SMB共享目录,或操作共享文件的方法代码如下:
csharpusing System;using org.apache.commons.net.nfs.Nfs;using org.apache.commons.net.nfs.NfsFile;
class Program{ static void Main(string[] args) { string sharePath=@\\your_server\share_name; string remotePath=@path\on\share; string localPath=@C:\local\path;
// 创建NfsClient实例 NfsClient nfsClient=new NfsClient();
try { // 连接到共享目录 nfsClient.connect(sharePath);
// 获取共享目录信息 NfsFile file=nfsClient.getfile(remotePath);
// 根据需要操作文件,例如下载、上传等 // 示例:下载文件 byte[] fileData=file.read(0, file.length());
// 将文件数据写入本地文件 System.IO.File.WriteAllBytes(localPath, fileData);
Console.WriteLine(文件操作成功。); } catch (Exception ex) { Console.WriteLine(操作失败: + ex.Message); } finally { // 断开连接 nfsClient.disconnect(); } }}
本文主要介绍.NET Core中,使用SharpCifs访问windows共享目录或smb协义共享目录,或操作共享文件的方法代码。
原文地址:.NET Core(C#)通过SharpCifs访问操作Windows(smb)共享目录方法代码
本文共计238个文字,预计阅读时间需要1分钟。
在.NET Core中,使用SharpCifs库访问Windows共享目录或SMB共享目录,或操作共享文件的方法代码如下:
csharpusing System;using org.apache.commons.net.nfs.Nfs;using org.apache.commons.net.nfs.NfsFile;
class Program{ static void Main(string[] args) { string sharePath=@\\your_server\share_name; string remotePath=@path\on\share; string localPath=@C:\local\path;
// 创建NfsClient实例 NfsClient nfsClient=new NfsClient();
try { // 连接到共享目录 nfsClient.connect(sharePath);
// 获取共享目录信息 NfsFile file=nfsClient.getfile(remotePath);
// 根据需要操作文件,例如下载、上传等 // 示例:下载文件 byte[] fileData=file.read(0, file.length());
// 将文件数据写入本地文件 System.IO.File.WriteAllBytes(localPath, fileData);
Console.WriteLine(文件操作成功。); } catch (Exception ex) { Console.WriteLine(操作失败: + ex.Message); } finally { // 断开连接 nfsClient.disconnect(); } }}
本文主要介绍.NET Core中,使用SharpCifs访问windows共享目录或smb协义共享目录,或操作共享文件的方法代码。
原文地址:.NET Core(C#)通过SharpCifs访问操作Windows(smb)共享目录方法代码

