如何通过身份验证将文件从服务器复制到本地 [英] How Do I Copy Files From Server To Local With Authentication
本文介绍了如何通过身份验证将文件从服务器复制到本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查网络上共享的其他计算机系统文件中的文本文件,并将一些文件从网络系统复制到本地。
我使用此代码
Hi,
I need to check text file from other computer system file that is sharing on network, and copy some file from network system to local.
I use this code
private string strDestination = @"C:\Program Files\SASystem\SASystem";
private string strSource = @"\\192.192.11.250\ver\IIversion\_New";
删除本地文件
delete local file
private void DeleteFilesFromDirectory(string directoryPath)
{
DirectoryInfo d = new DirectoryInfo(directoryPath);
foreach (FileInfo fi in d.GetFiles())
{
fi.Delete();
}
foreach (DirectoryInfo di in d.GetDirectories())
{
DeleteFilesFromDirectory(di.FullName);
di.Delete();
}
}
check txt file
check txt file
//Check Current Version
string Current_Version = AssemblyName.GetAssemblyName(strDestination + @"\SASystem.exe").Version.ToString();
//Check New Version
StreamReader wr = File.OpenText(@"\\192.192.11.250\ver\IIversion\New_Version.txt");
string New_version = wr.ReadToEnd();
wr.Close();
int Current = Convert.ToInt32(Current_Version.Replace(".", ""));
int New = Convert.ToInt32(New_version.Replace(".", ""));
if (New > Current)
{
if (MessageBox.Show("New version is available on server, Do you want to Upgrade current Version? ", "New Version", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.Opacity = 100;
}
else
{
//System.Diagnostics.Process.Start(strDestination + @"\SASystem.exe");
Application.ExitThread();
}
}
else
{
System.Diagnostics.Process.Start(strDestination + @"\SASystem.exe");
Application.ExitThread();
}
复制文件
copy file
private void copyDirectory(string strSource, string strDestination)
{
bUpdat.Text = "Skip";
// searches current directory and sub directory
int fCount = Directory.GetFiles(strSource, "*.*", SearchOption.AllDirectories).Length;
// MessageBox.Show(fCount+"");
progressBar1.Maximum = fCount;
if (!Directory.Exists(strDestination))
{
Directory.CreateDirectory(strDestination);
}
DirectoryInfo dirInfo = new DirectoryInfo(strSource);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo tempfile in files)
{
Application.DoEvents();
if (bUpdat.Text == "Skip")
{
progressBar1.PerformStep();
tempfile.CopyTo(Path.Combine(strDestination, tempfile.Name));
}
Application.DoEvents();
}
DirectoryInfo[] dirctororys = dirInfo.GetDirectories();
foreach (DirectoryInfo tempdir in dirctororys)
{
if (bUpdat.Text == "Skip")
{
copyDirectory(Path.Combine(strSource, tempdir.Name), Path.Combine(strDestination, tempdir.Name));
}
Application.DoEvents();
}
progressBar1.Value = 0;
bUpdat.Text = "Upgrade ";
}
有没有人帮我修改此代码?感谢您的关注!
Is there anyone help me to modify this code? thanks for attention!
推荐答案
这篇关于如何通过身份验证将文件从服务器复制到本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文