PDA

View Full Version : کپی کردن فایل ها از پوشه شیر شده در شبکه محلی با احراز هویت



soleimani.em
پنج شنبه 28 فروردین 1393, 12:52 عصر
سلام به دوستان من از این کد برای چک کردن و کپی کردن فایل های موجود در پوشه شیر شده در شبکه محلی استفاده کردم منتها یه مشکلی دارم برای احراز هویت که کامپیوتری که اطلاعات روش هست یوزر و پسورد میخاد.
دوستان اگه راهنماییم کنید یا کدها رو برام اصلاح کنید ممنون میشم
آدرس ها


private string strDestination = @"C:\Program Files\SASystem\SASystem";
private string strSource = @"\\192.192.11.250\ver\IIversion\_New";

حذف فایلهای قدیمی سیستم


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 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();
}

کپی کردن فایل ها از شبکه نیاز به احراز هویت


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 ";

}

iman_me
پنج شنبه 28 فروردین 1393, 14:21 عصر
شبکه دامینه؟

soleimani.em
پنج شنبه 28 فروردین 1393, 14:23 عصر
برا هردوشون الان غیر دامینه ولی یکی دو ماه دیگه دامین میشه.

iman_me
پنج شنبه 28 فروردین 1393, 14:27 عصر
ورک پگروپ امنیت نداره یا من نتونستم درستش کنم


private void CopyFile(string FileSource,DevComponents.DotNetBar.Controls.Progre ssBarX progressBar1)
{
int NumRead;
long FileLength;
FileStream From = new FileStream(FileSource, FileMode.Open);
System.IO.FileStream To = new System.IO.FileStream(@"D:\Test\"+SPath,
System.IO.FileMode.CreateNew);
byte[] buffer = new byte[1024];
FileLength = From.Length;
progressBar1.Minimum = 0;
progressBar1.Maximum = (int)FileLength;
while (FileLength > 0)
{
System.IO.BinaryReader Reader = new System.IO.BinaryReader(From);
NumRead = Reader.Read(buffer, 0, 1024);
FileLength = FileLength - NumRead;
System.IO.BinaryWriter Writer = new System.IO.BinaryWriter(To);
Writer.Write(buffer, 0, NumRead);
FileInfo aaaa = new FileInfo(FileSource);
Int64 a = aaaa.Length;
Int64 a1 = a /= 1000;
//MessageBox.Show(a1.ToString());
progressBar1.Text = aaaa.Name;
progressBar1.Maximum = int.Parse(a1.ToString());
progressBar1.Value = progressBar1.Value + (NumRead /= 1000);


Writer.Flush();
}
From.Close();
To.Close();

if (progressBar1.Value > 99)
{
progressBar1.Value = 0;
}
}

soleimani.em
پنج شنبه 28 فروردین 1393, 14:41 عصر
ایمان جان اگه بخوام اینو تو کدهای خودم بگنجانم چیکار باید بکنم؟ بعد این کد تست شده توسط خودتون چون جایی یوزر و پسورد نخواسته؟ من تو کدهای بالا ارور یوزر و پسورد اشتباه رو میگیرم.

soleimani.em
یک شنبه 31 فروردین 1393, 13:22 عصر
کسی نیست مرا راهنمایی کند؟