static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; string sifre = null; string kullanici = null; string[] files = Directory.GetFiles(@"files\"); basadon : Console.Write("Get Command > "); command = Console.ReadLine(); if (command.IndexOf("view server") == 0) { Console.WriteLine(""); string[] Dosyalar = null; StringBuilder result = new StringBuilder(); FtpWebRequest FTP; // yol = "ftp://" + website + "/" + command.Replace(0,) + "/"; try { learn(); FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(yol)); FTP.UseBinary = true; FTP.Credentials = new NetworkCredential(kullanici, sifre); FTP.Method = WebRequestMethods.Ftp.ListDirectory; WebResponse response = FTP.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string line = reader.ReadLine(); while (line != null) { result.Append(line); result.Append("\n"); line = reader.ReadLine(); } result.Remove(result.ToString().LastIndexOf('\n'), 1); reader.Close(); response.Close(); Dosyalar = result.ToString().Split('\n'); foreach (string dosya in Dosyalar) { if (dosya.IndexOf(".") != -1) { Console.WriteLine(" [F] " + dosya.ToString()); Console.WriteLine(""); } else { Console.WriteLine(" [D] " + dosya.ToString()); string[] Dosyalar2; StringBuilder result2 = new StringBuilder(); FtpWebRequest FTP2; try { FTP2 = (FtpWebRequest)FtpWebRequest.Create(new Uri(yol + @"\" + dosya)); FTP2.UseBinary = true; FTP2.Credentials = new NetworkCredential(kullanici, sifre); FTP2.Method = WebRequestMethods.Ftp.ListDirectory; WebResponse response2 = FTP2.GetResponse(); StreamReader reader2 = new StreamReader(response2.GetResponseStream()); string line2 = reader2.ReadLine(); while (line2 != null) { result2.Append(line2); result2.Append("\n"); line2 = reader2.ReadLine(); } result2.Remove(result2.ToString().LastIndexOf('\n'), 1); reader2.Close(); response2.Close(); Dosyalar2 = result2.ToString().Split('\n'); foreach (string dosya2 in Dosyalar2) { if (dosya2.IndexOf(".") != -1) { Console.WriteLine(" [F] " + dosya2.ToString()); } else { Console.WriteLine(" [D] " + dosya2.ToString()); } } } catch { } Console.WriteLine(""); } } } catch { Console.WriteLine("[System] > Folder empty"); } } else if (command == "view folder") { foreach (string file in files) { Console.WriteLine("[All] " + file); } } else if (command.IndexOf("upload to server") == 0) { learn(); foreach (string file in files) { FileInfo FI = new FileInfo(file); // Dosyanın gönderileceği ftp yolunu belirliyoruz string uri = yol + "/" + FI.Name; // Ftp işlemlerini yapacağımız sınıfımızı tanımlıyoruz FtpWebRequest FTP; // Oluşturduğumuz değişkene hedef yolumuzu gösteriyoruz FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); // Ftp bağlantısı için gerekli bilgileri belirliyoruz FTP.Credentials = new NetworkCredential(kullanici, sifre); // Default olarak true geliyor false 'a çeviriyoruz. Amacımız bağlantı açıksa hataya düşmemesi FTP.KeepAlive = false; // Bu kısımda hangi işlemi yapacağımızı belirtiyoruz, dosya göndereceğimiz için UploadFile methodunu seçiyoruz FTP.Method = WebRequestMethods.Ftp.UploadFile; // Dosya tranferinin Binary türden yapılacağını belirtiyoruz FTP.UseBinary = true; // Gönderdiğimiz dosyanın boyutunu belirtiyoruz FTP.ContentLength = FI.Length; // Buffer büyüklüğünü 2KB olarak belirtiyoruz ve değişkenimizi tanımlıoyruz int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Bu kısımda dosyayı binary'e çevirip ftp'ye gönderiyoruz FileStream FS = FI.OpenRead(); try { Stream strm = FTP.GetRequestStream(); contentLen = FS.Read(buff, 0, buffLength); while (contentLen != 0)//dosya bitene kadar gönderme işlemi { strm.Write(buff, 0, contentLen); contentLen = FS.Read(buff, 0, buffLength); } strm.Close(); FS.Close(); Console.WriteLine("[System] > Operation is completed"); } catch (Exception ex) { Console.WriteLine(ex.Message, "Hata"); } } } else if (command.IndexOf("remove on server") == 0) { learn(); if (FileorFolder == false) { WebRequest FTP; try { FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(yol)); FTP.Credentials = new NetworkCredential(kullanici, sifre); FTP.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse response = (FtpWebResponse)FTP.GetResponse(); Console.WriteLine(response.StatusDescription); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { FtpWebRequest FTP; try { Console.WriteLine(yol); FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(yol + "/")); FTP.UseBinary = true; FTP.Credentials = new NetworkCredential(kullanici, sifre); FTP.UsePassive = true; FTP.Method = WebRequestMethods.Ftp.RemoveDirectory; FtpWebResponse response = (FtpWebResponse)FTP.GetResponse(); Console.WriteLine(response.StatusDescription); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } else if (command.IndexOf("create on server") == 0) { learn(); FtpWebRequest FTP; try { Console.Write("Get Name > "); swfolder = Console.ReadLine(); FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(yol + "/" + swfolder)); FTP.UseBinary = true; FTP.Credentials = new NetworkCredential(kullanici, sifre); FTP.Method = WebRequestMethods.Ftp.MakeDirectory; FtpWebResponse response = (FtpWebResponse)FTP.GetResponse(); Console.WriteLine(response.StatusDescription); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else if (command.IndexOf("rename on server") == 0) { learn(); Console.Write("Get new label > "); swfolder = Console.ReadLine(); FtpWebRequest FTP; try { FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(yol)); FTP.UseBinary = true; FTP.RenameTo = swfolder; FTP.Credentials = new NetworkCredential(kullanici, sifre); FTP.Method = WebRequestMethods.Ftp.Rename; FtpWebResponse response = (FtpWebResponse)FTP.GetResponse(); Console.WriteLine(response.StatusDescription); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else if (command == "con") { website = "gauncher.com"; kullanici = "gauncher"; sifre = "cryxleaderDatabase7"; Console.WriteLine("[System] > Saved"); } else if (command == "userpass") { Console.Write("Website > "); website = Console.ReadLine(); Console.Write("Username > "); kullanici = Console.ReadLine(); Console.Write("Password > "); sifre = Console.ReadLine(); Console.WriteLine("[System] > Saved"); } else if (command == "exit" || command == "/q") { Environment.Exit(0); } else if (command == "console clear" || command == "/cc") { Console.Clear(); } else if (command == "options") { Console.WriteLine("[System] > This content null"); } else if (command == "help") { Console.WriteLine("[Command] > view server : Server dosyalarını görüntüle"); Console.WriteLine("[Command] > view folder : Klasördeki dosyaları görüntüle"); Console.WriteLine("[Command] > upload to server : Klasördeki dosyaları servera yükle"); Console.WriteLine("[Command] > remove on server : Server üzerinde dosya sil"); Console.WriteLine("[Command] > create on server : Server üzerinde dosya oluştur"); Console.WriteLine("[Command] > rename on server : Server üzerinde dosyaya yeni isim ver"); Console.WriteLine("[Command] > con : Oto bağlan"); Console.WriteLine("[Command] > userpass : Bilgileri değiştir"); Console.WriteLine("[Command] > exit & /q : Çıkış"); Console.WriteLine("[Command] > console clear & /cc : Konsol ekranını temizle"); Console.WriteLine("[Command] > options : Ayarlar"); } else { Console.Write("[System] > Command unresolved, try again"); Console.WriteLine(); } goto basadon; }
public string DownloadProtocolPacketStart(string Donen) { Int64 iRunningByteTotal = 0; try { Connect = new SqlConnection(ConnectText); string Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string[] DosyaListesi; StringBuilder result = new StringBuilder(); FtpWebRequest FTP; FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPServer)); FTP.UseBinary = true; FTP.Credentials = new NetworkCredential(Admin, Password); FTP.Method = WebRequestMethods.Ftp.ListDirectory; WebResponse response = FTP.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string line = reader.ReadLine(); while (line != null) { result.Append(line); result.Append("\n"); line = reader.ReadLine(); } result.Remove(result.ToString().LastIndexOf('\n'), 1); reader.Close(); response.Close(); DosyaListesi = result.ToString().Split('\n'); for (int x = 0; x < DosyaListesi.Count(); x++) { int kntrl = 0; for (int i = 0; i < DosyaListesi[x].Length; i++) { if (DosyaListesi[x][i].ToString() == ".") { kntrl = 1; } } if (kntrl == 1) { FileStream SR = new FileStream(Path + "\\" + DosyaListesi[x].ToString(), FileMode.Create); FtpWebRequest FTPi0; FTPi0 = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPServer + DosyaListesi[x].ToString())); FTPi0.Credentials = new NetworkCredential(Admin, Password); FTPi0.Method = WebRequestMethods.Ftp.DownloadFile; FTPi0.UseBinary = true; FtpWebResponse response2 = (FtpWebResponse)FTPi0.GetResponse(); Stream ftpStream = response2.GetResponseStream(); long cl = response2.ContentLength; int bufferSize = 1024; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); //DownloadTransProceses(readCount.ToString()); iRunningByteTotal += bufferSize; double dIndex = (double)(iRunningByteTotal); double dTotal = (double)buffer.Length; double dProgressPercentage = (dIndex / dTotal); int iProgressPercentage = (int)(dProgressPercentage * 100); while (readCount > 0) { SR.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); //DownloadTransProceses(readCount.ToString()); } ftpStream.Close(); SR.Close(); response2.Close(); //DownloadTransProceses(readCount.ToString()); DownloadTransTexts("Dosya İndi" + DosyaListesi[x].ToString()); } else { FtpWebRequest FTP2; Directory.CreateDirectory(Path + "\\" + DosyaListesi[x]); string[] DosyaListesi2; FTP2 = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPServer + DosyaListesi[x])); FTP2.UseBinary = true; FTP2.Credentials = new NetworkCredential(Admin, Password); StringBuilder result2 = new StringBuilder(); FTP2.Method = WebRequestMethods.Ftp.ListDirectory; WebResponse response3 = FTP2.GetResponse(); StreamReader reader3 = new StreamReader(response3.GetResponseStream()); string line3 = reader3.ReadLine(); while (line3 != null) { result2.Append(line3); result2.Append("\n"); line3 = reader3.ReadLine(); } result2.Remove(result2.ToString().LastIndexOf('\n'), 1); reader3.Close(); response3.Close(); DosyaListesi2 = result2.ToString().Split('\n'); for (int y = 0; y < DosyaListesi2.Length; y++) { kntrl = 0; for (int i = 0; i < DosyaListesi2[y].Length; i++) { if (DosyaListesi2[y][i].ToString() == ".") { kntrl = 1; } } if (kntrl == 1) { try { FileStream SR = new FileStream(Path + "\\" + DosyaListesi[x].ToString() + "\\" + DosyaListesi2[y].ToString(), FileMode.Create); FtpWebRequest FTPi0; FTPi0 = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPServer + DosyaListesi[x].ToString() + @"/" + DosyaListesi2[y].ToString())); FTPi0.Credentials = new NetworkCredential(Admin, Password); FTPi0.Method = WebRequestMethods.Ftp.DownloadFile; FTPi0.UseBinary = true; FTPi0.Method = WebRequestMethods.Ftp.DownloadFile; FTPi0.UseBinary = true; FtpWebResponse response2 = (FtpWebResponse)FTPi0.GetResponse(); Stream ftpStream2 = response2.GetResponseStream(); long cl = response2.ContentLength; int bufferSize = 1024; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream2.Read(buffer, 0, bufferSize); DownloadTransProceses(readCount.ToString()); DownloadTransTexts("Dosya İndiriliyor" + DosyaListesi[x].ToString()); while (readCount > 0) { SR.Write(buffer, 0, readCount); readCount = ftpStream2.Read(buffer, 0, bufferSize); DownloadTransProceses(readCount.ToString()); } ftpStream2.Close(); SR.Close(); response2.Close(); } catch { DownloadTransErrors("Bir sorun oluştu.Dosya indirme işlemi sonlandırıldı."); } DownloadTransProceses("-1"); DownloadTransTexts("Dosya İndi" + DosyaListesi[x].ToString()); response3.Close(); response.Close(); } } } } DownloadTransTexts("Tüm Dosyalar İndirildi"); System.Threading.Thread.Sleep(2000); } catch { DownloadTransErrors("Güncelleme yapılamadı.Lütfen internet bağlantısının ya da sistemin doğru çalıştığından emin olunuz.");; } return(DownloadTransTexts("Güncelleme işlemi bitmiştir.")); }
void download() { try { int totalReadBytesCount = 0; string[] DosyaListesi; StringBuilder result = new StringBuilder(); FtpWebRequest FTP; FTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpdown)); // Dosya tranferinin Binary türden yapılacağını belirtiyoruz FTP.UseBinary = true; // Ftp bağlantısı için UserName ve Şifremizi belirtiyoruz FTP.Credentials = new NetworkCredential(kullanici, sifre); // Bu kısımda hangi işlemi yapacağımızı belirtiyoruz FTP.Method = WebRequestMethods.Ftp.ListDirectory; FTP.Method = WebRequestMethods.Ftp.ListDirectory; // Dosya listesini alıyoruz WebResponse response = FTP.GetResponse(); // Aldığımız listeyi StreamReader ile her satırını okuyup dosya isimlerini ayırıyoruz StreamReader reader = new StreamReader(response.GetResponseStream()); string line = reader.ReadLine(); while (line != null) { result.Append(line); result.Append("\n"); line = reader.ReadLine(); } result.Remove(result.ToString().LastIndexOf('\n'), 1); reader.Close(); response.Close(); DosyaListesi = result.ToString().Split('\n'); FtpWebResponse response5 = null; for (int x = 0; x < DosyaListesi.Count(); x++) { FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpdown + DosyaListesi[x].ToString())); request.Proxy = null; request.Credentials = new NetworkCredential(kullanici, sifre); request.Method = WebRequestMethods.Ftp.GetFileSize; response5 = (FtpWebResponse)request.GetResponse(); size += response5.ContentLength; } response5.Close(); progressBar1.Maximum = Convert.ToInt32(size); label2.Text = "Dosyalar İndiriliyor..."; for (int x = 0; x < DosyaListesi.Count(); x++) { int kntrl = 0; for (int i = 0; i < DosyaListesi[x].Length; i++) { if (DosyaListesi[x][i].ToString() == ".") { kntrl = 1; } } if (kntrl == 1) { FileStream SR = new FileStream(Application.StartupPath + "\\" + DosyaListesi[x].ToString(), FileMode.Create); FtpWebRequest FTPi0; FTPi0 = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpdown + DosyaListesi[x].ToString())); FTPi0.Credentials = new NetworkCredential(kullanici, sifre); FTPi0.Method = WebRequestMethods.Ftp.DownloadFile; FTPi0.UseBinary = true; FtpWebResponse response2 = (FtpWebResponse)FTPi0.GetResponse(); Stream ftpStream = response2.GetResponseStream(); long cl = response2.ContentLength; int bufferSize = 1024; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream.Read(buffer, 0, bufferSize); progressBar1.Value += readCount; label1.Text = "Dosya İndiriliyor...: " + DosyaListesi[x].ToString(); while (readCount > 0) { SR.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); progressBar1.Value += readCount; } ftpStream.Close(); SR.Close(); response2.Close(); label1.Text = "Dosya İndi...: " + DosyaListesi[x].ToString(); } else { FtpWebRequest FTP2; Directory.CreateDirectory(Application.StartupPath + "\\" + DosyaListesi[x]); string[] DosyaListesi2; FTP2 = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpdown + DosyaListesi[x])); FTP2.UseBinary = true; FTP2.Credentials = new NetworkCredential(kullanici, sifre); StringBuilder result2 = new StringBuilder(); FTP2.Method = WebRequestMethods.Ftp.ListDirectory; WebResponse response3 = FTP2.GetResponse(); StreamReader reader3 = new StreamReader(response3.GetResponseStream()); string line3 = reader3.ReadLine(); while (line3 != null) { result2.Append(line3); result2.Append("\n"); line3 = reader3.ReadLine(); } result2.Remove(result2.ToString().LastIndexOf('\n'), 1); reader3.Close(); response3.Close(); DosyaListesi2 = result2.ToString().Split('\n'); for (int y = 0; y < DosyaListesi2.Length; y++) { kntrl = 0; for (int i = 0; i < DosyaListesi2[y].Length; i++) { if (DosyaListesi2[y][i].ToString() == ".") { kntrl = 1; } } if (kntrl == 1) { try { FileStream SR = new FileStream(Application.StartupPath + "\\" + DosyaListesi[x].ToString() + "\\" + DosyaListesi2[y].ToString(), FileMode.Create); FtpWebRequest FTPi0; FTPi0 = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpdown + DosyaListesi[x].ToString() + @"/" + DosyaListesi2[y].ToString())); FTPi0.Credentials = new NetworkCredential(kullanici, sifre); FTPi0.Method = WebRequestMethods.Ftp.DownloadFile; FTPi0.UseBinary = true; FTPi0.Method = WebRequestMethods.Ftp.DownloadFile; FTPi0.UseBinary = true; FtpWebResponse response2 = (FtpWebResponse)FTPi0.GetResponse(); Stream ftpStream2 = response2.GetResponseStream(); long cl = response2.ContentLength; int bufferSize = 1024; int readCount; byte[] buffer = new byte[bufferSize]; readCount = ftpStream2.Read(buffer, 0, bufferSize); progressBar1.Value += readCount; label1.Text = "Dosya İndiriliyor...: " + DosyaListesi[x].ToString() + "\\" + DosyaListesi2[y].ToString(); while (readCount > 0) { SR.Write(buffer, 0, readCount); readCount = ftpStream2.Read(buffer, 0, bufferSize); progressBar1.Value += readCount; } ftpStream2.Close(); SR.Close(); response2.Close(); } catch {; } label1.Text = "Dosya İndi...: " + DosyaListesi[x].ToString() + "\\" + DosyaListesi2[y].ToString(); response3.Close(); response.Close(); } } } } System.Threading.Thread.Sleep(2000); } catch { MessageBox.Show("Güncelleme yapılamadı.Lütfen internet bağlantısının ya da sistemin doğru çalıştığından emin olunuz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } if (MessageBox.Show("Sisteminiz Güncellendi.Sisteminiz yeniden başlatılacaktır.Şimdi Başlatmak istiyor musunuz ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { System.Diagnostics.Process.Start(Application.StartupPath + "\\FlowTürk Görsel Programlama Simülatörü.exe"); Application.Exit(); } else { Application.Exit(); } }