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 ...
随机推荐
- SSL/TSL握手过程详解
1. Client Hello 握手第一步是客户端向服务端发送 Client Hello 消息,这个消息里包含了一个客户端生成的随机数 Random1.客户端支持的加密套件(Support Ciphe ...
- Ubuntu下navicat过期解决办法
Ubuntu下使用navicat过期.试用期是15天. 可以删除.navicat64/解决.不好的一点就是.需要重新连接数据库,以前的连接记录会被删除 rm -rf ~/.navicat64/
- C语言的 32个关键之和9个控制语言之关键字
auto break case char const continue default do double else enum extern float for goto ...
- devise 自定义手机号登录
user model中配置 validates_uniqueness_of :phone def email_required? false end 修改user migration文件,给phone ...
- 33Sql数据删除与遍历
数据库的创建.添加.修改.查询.删除都是利用SQL语句和类QSqlQuery的结合. QSqlDatabase::database().可返回当前正在打开的数据库对象. 数据库的删除 //获取删除的名 ...
- uva1291
这题说的给了 一 个 图,每次 按照他给的顺序 跳格子 给了 每种 格子之间的 转换 代价 求最后 转换代价 dp[i][j] 表示 左脚在i 右脚 在j 的最小代价 然后用滚动数组 ,就可以不断说的 ...
- ts 绘制多边形
let bg = this.createBitmapByName("123_png"); this.addChild(bg) bg.x = this.stage.width / 2 ...
- 使用spring cache和ehcache之前必须了解的
好长时间没写博客了,真的是没时间啊.ps:其实就是懒!!接下来几篇要写下缓存,这里主要写下ehcache与spring整合的内容,包括aop形式的缓存,基于注解的缓存,页面缓存这三方面吧.在这之前先要 ...
- fiddler抓包HTTPS配置及代理设置
使用fiddler抓包过程中遇到一系列的问题,浪费了大半天时间~~~写下解决办法 按照网上方法配置之后还是无法抓到cookies提示各种证书错误 1.卸载fiddler重新安装,设置 2.设置步骤 ( ...
- HDU4112
对于n*m*k的方块,用手掰成1**1的那么搜需要的步骤是固定的,为n*m*k-,如果用刀切,因为可以把多块叠在一起切,所以对于长度为n的,将他切成0,所需要的步骤数位k 对于n*m*k的方块,用手掰 ...