c# 通过文件夹共享复制文件到服务器
public static string[] GetFileNames(string directoryPath, string searchName)
{
return Directory.GetFiles(directoryPath, searchName, SearchOption.AllDirectories);
}
public class NetFileConntion
{
public static bool ConnectState(string path)
{
return ConnectState(path, "", "");
} public static bool ConnectState(string path, string userName, string passWord)
{
bool flag = false;
Process proc = new Process();
try
{
proc.StartInfo.FileName = " cmd.exe ";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = @"net use * /del /y
net use " + path + " /User:" + userName + " " + passWord + " /PERSISTENT:YES";
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine(" exit ");
while (!proc.HasExited)
{
proc.WaitForExit();
}
string errormsg = proc.StandardError.ReadToEnd();
proc.StandardError.Close();
if (string.IsNullOrEmpty(errormsg))
{
flag = true;
}
else
{
throw new Exception(errormsg);
}
}
finally
{
proc.Close();
proc.Dispose();
}
return flag;
}
}
/// <summary>
/// 数据处理
/// </summary>
public override void Execute(JobExcutePara para)
{
if (ConfigHelper.Settings("RemoteCopyFileSwitch") != "")
{
return;
} //读取所有文件
var files = DirFileHelper.GetFileNames(ExcelRootPath, "*.*").Where(t => t.Contains("\\U_")).ToList();
//远程地址
var remotepaths = ConfigHelper.Settings("RemoteRootPaths")
.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
var remoteusers = ConfigHelper.Settings("RemoteUserPass")
.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
var sr=new StringBuilder();
foreach (var remotepath in remotepaths)
{
sr.Append(remotepath + ",");
try
{
bool status = NetFileConntion.ConnectState(remotepath, remoteusers[], remoteusers[]);
sr.Append(status + "," + files.Count + "," + remoteusers[] + "," + remoteusers[]);
if (status)
{
var startTime = new DateTime(DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day,
, , );
//读取目标目录文件
var theFiles = DirFileHelper.GetFileNames(remotepath, "*.*");
sr.Append(theFiles.Length + ","); foreach (var file1 in files)
{
var fileinfo_1=new FileInfo(file1);
if (fileinfo_1.LastWriteTime < startTime)
{
continue;
}
var filepath = file1.Replace(ExcelRootPath, string.Empty);
var flag = false;
foreach (var file2 in theFiles)
{
//检查文件是否存在
if (file2.Contains(filepath))
{
flag = true;
break;
}
}
if (!flag)
{
//没有则进行写入复制
var targetPath = remotepath + filepath;
if (!Directory.Exists(Path.GetDirectoryName(targetPath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
}
File.Copy(file1, targetPath);
}
}
}
}
catch (Exception ex)
{
LogHelper._Error("JobExcute__CopyFile ERROR", ex);
}
}
//LogHelper._Info(sr.ToString());
}
c# 通过文件夹共享复制文件到服务器的更多相关文章
- java-FileUtils(复制文件夹、复制文件、字符串直接写入文件中)(新手)
实例: lx1: import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; pu ...
- C# 把一个文件夹下所有文件复制到另一个文件夹下 把一个文件夹下所有文件删除(转)
C# 把一个文件夹下所有文件复制到另一个文件夹下 public static void CopyDirectory(string srcPath, string destPath) { try { ...
- VMWare12虚拟机实现主客机间的文件拖拽(复制粘贴)和文件夹共享
版本: 主机:Windows 7 64位旗舰版 虚拟机: VMWare 12 + Windows 7 64位旗舰版 VMWare pro 12 + Ubuntu16.04LTS 64位 注:由于VMW ...
- 解决WIN7与虚拟机CentOS的文件夹共享问题
一.系统与软件 WIN7 64bit.VirtualBox 5.0.14.CentOS 6.5.SecureCRT 7.2.3 二.使用文件夹共享需要安装增强功能,但是安装时无法读取光盘iso文件 三 ...
- 负载均衡下的资源文件配置/多站点下的资源文件夹共享(Windows IIS)
前言: 负载均衡用的是NLB,微软的方案不太靠谱,举个例子吧,AB两台服务器负载出C,如果用户访问访问C之后分配的是A,那么如果A挂了,是不会自动切换到B的.据说后来还有一种NLB的方案可以实现,也不 ...
- win7文件夹共享(不新建账户、不带密码直接访问)
1.右键需要共享的文件夹>共享>特定用户>选择Everyone>“添加”>“共享” 2.打开控制面板>按类别的查看方式>网络和Internet下的选择家庭组和 ...
- Powershell学习之道-文件夹共享及磁盘映射
导读 在Linux环境下,我们很轻易就能得心应手地通过命令操作一切事物,在Windows下,Powershell也算是后起之秀,提供大量的cmdlet以及c#的横向拓展.下面将由小编带领大家通过Pow ...
- linux下跨服务器文件文件夹的复制
文件的复制:scp –P (端口号) ./authorized_keys berchina@hadoop002:/home/berchina 文件夹的复制:scp -r -P (端口号) /home/ ...
- MFC下对文件及文件夹的操作(复制、剪切、删除、创建文件夹,写文件)
一.文件夹的创建 void CFileOperationDlg::OnButtonMakeFolder() { // TODO: Add your control notification handl ...
随机推荐
- eval(PHP 4, PHP 5)
eval — 把字符串作为PHP代码执行 说明 mixed eval ( string $code_str ) 把字符串 code_str 作为PHP代码执行. 除了其他,该函数能够执行储存于数据库文 ...
- WebStorm mac下如何安装WebStorm + 破解
1.下载软件最好的地址就是官网了下载地址 选择好系统版本以后点击DOWNLOAD 下载Webstorm 2.安装双击下载好的安装包.将WebStromt拖入application文件夹,然后在La ...
- (1)R介绍
1. R初窥 从CRAN(The Comprehensive R Archive Network)cran.r-project.org—mirrors.html中选择一个镜像,然后下载合适的安装包(R ...
- Sparsity稀疏编码(三)
稀疏编码(sparse coding)和低秩矩阵(low rank)的区别 上两个小结介绍了稀疏编码的生命科学解释,也给出一些稀疏编码模型的原型(比如LASSO),稀疏编码之前的探讨文章 ...
- Hadoop HDFS的Shell操作实例
本文发表于本人博客. 我们知道HDFS是Hadoop的分布式文件系统,那既然是文件系统那最起码会有管理文件.文件夹之类的功能吧,这个类似我们的Windows操作系统一样的吧,创建.修改.删除.移动.复 ...
- HDU——2955 Robberies (0-1背包)
题意:有N个银行,每抢一个银行,可以获得\(v_i\)的前,但是会有\(p_i\)的概率被抓.现在要把被抓概率控制在\(P\)之下,求最多能抢到多少钱. 分析:0-1背包的变形,把重量变成了概率,因为 ...
- Spring-Boot 中 Redis 的简单使用以及简单模糊匹配删除
https://yulaiz.com/spring-boot-redis-simple/
- 20145315 《Java程序设计》第七周学习总结
20145315 <Java程序设计>第七周学习总结 教材学习内容总结 第十三章 时间与日期 13.1.1时间的度量 1.格林威治时间(GMT):参考太阳到达最高点,有时间误差. 2.世界 ...
- 20145319 《网络渗透》MS11-050漏洞渗透
20145319 <网络渗透>MS11-050漏洞渗透 一 实验内容 初步掌握平台matesploit的使用 有了初步完成渗透操作的思路 了解MS11_050相关知识: - 安全公告:KB ...
- python常见容器属性和方法
`````字符串中反斜杠字符表 转义格式 意义 \' 单引号(') \" 双引号(") \\ 反斜杠(\ ) \n 换行 \r 返回光标至行首 \f 换页 \t ...