C# Windows Form ile ftp upload yapmak
30 Mart 2018 / 12:41
Burak
C# da windows form üzerinden ftp üzerinde upload yapmak isterseniz aşağıdaki fonksiyonu kullanabilirsiniz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public string dosyaupload(string dosyaAdi) { string ftpServerIP = "host url"; //www.google.com FileInfo dosyaBilgisi = new FileInfo(dosyaAdi); string uri = "ftp://" + ftpServerIP + "/" + dosyaBilgisi.Name; FtpWebRequest ftpIstegi; ftpIstegi = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "" + dosyaBilgisi.Name)); ftpIstegi.Credentials = new NetworkCredential("ftp kad", "ftp sifre"); ftpIstegi.KeepAlive = false; ftpIstegi.Method = WebRequestMethods.Ftp.UploadFile; ftpIstegi.UseBinary = true; ftpIstegi.ContentLength = dosyaBilgisi.Length; int bufferUzunlugu = 2048; byte[] buff = new byte[10000000]; int sayi; FileStream stream = dosyaBilgisi.OpenRead(); Stream str = ftpIstegi.GetRequestStream(); sayi = stream.Read(buff, 0, bufferUzunlugu); while (sayi != 0) { str.Write(buff, 0, sayi); sayi = stream.Read(buff, 0, bufferUzunlugu); } str.Close(); stream.Close(); return ""; } |
Kullanımı buton yada bir eventa aşağıdaki kodları yapıştırın
1 2 3 |
OpenFileDialog op = new OpenFileDialog(); op.ShowDialog(); dosyaupload(op.FileName); |
Bu Yazılarıda Okuyabilirsiniz...
Bir cevap yazın