C# ile FTP'ye çoklu resim yükleme

openFileDialog sınıfı çoklu seçim (multiselect) şeklinde bir araştırma yaptınız mı? Örneğin şunun gibi
teşekkürler araştırma yaptım fakat ftp için bi çözüm bulamadım. (Çözüldü)

DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
button1.Text = "Yükleniyor...";
button1.Enabled = false;
progressBar1.Minimum = 0;
progressBar1.Maximum = openFileDialog1.FileNames.Count();
progressBar1.Value = 0;
foreach (String file in openFileDialog1.FileNames)
{
PictureBox pb = new PictureBox();
Image loadedImage = Image.FromFile(file);
pb.Image = loadedImage;
pb.SizeMode = PictureBoxSizeMode.Zoom;
flowLayoutPanel1.Controls.Add(pb);
uploadFile(file);
progressBar1.Value++;
}
MessageBox.Show("Resimler Yüklendi");
button1.Text = "Resim Seç/Yükle";
button1.Enabled = true;
 
Form initialize kısmında "openFileDialog1.Multiselect = true;" şeklinde belirtilebilir ya da. openfiledialog1 properties penceresisnde multiselect özelliği true yapılabilir. Sizin yazdığınız koddaki uploadFile() metodu aşağıdaki gibi olamalıdır. FTP url path doğru yazmanız lazım. Önce browserda ftp://www.url.com/www/ şeklinde girebiliyor musunuz bir deneyin.
Kod:
using System.Net;
using System.IO;
....
private static void uploadFile(string source)
        {
            try
            {
                string filename = Path.GetFileName(source);
                string ftpfullpath = "ftp://www.url.com/www/" + filename;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential("ftp_user_name", "ftp_password");

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileStream fs = File.OpenRead(source);
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                fs.Close();

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hata: " + ex.Message.ToString());
               // throw ex;
            }
        }
 
Form initialize kısmında "openFileDialog1.Multiselect = true;" şeklinde belirtilebilir ya da. openfiledialog1 properties penceresisnde multiselect özelliği true yapılabilir. Sizin yazdığınız koddaki uploadFile() metodu aşağıdaki gibi olamalıdır. FTP url path doğru yazmanız lazım. Önce browserda ftp://www.url.com/www/ şeklinde girebiliyor musunuz bir deneyin.
Kod:
using System.Net;
using System.IO;
....
private static void uploadFile(string source)
        {
            try
            {
                string filename = Path.GetFileName(source);
                string ftpfullpath = "ftp://www.url.com/www/" + filename;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential("ftp_user_name", "ftp_password");

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileStream fs = File.OpenRead(source);
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                fs.Close();

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hata: " + ex.Message.ToString());
               // throw ex;
            }
        }
sorun çözüldü yardım için teşekkürler
 
Form initialize kısmında "openFileDialog1.Multiselect = true;" şeklinde belirtilebilir ya da. openfiledialog1 properties penceresisnde multiselect özelliği true yapılabilir. Sizin yazdığınız koddaki uploadFile() metodu aşağıdaki gibi olamalıdır. FTP url path doğru yazmanız lazım. Önce browserda ftp://www.url.com/www/ şeklinde girebiliyor musunuz bir deneyin.
Kod:
using System.Net;
using System.IO;
....
private static void uploadFile(string source)
        {
            try
            {
                string filename = Path.GetFileName(source);
                string ftpfullpath = "ftp://www.url.com/www/" + filename;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential("ftp_user_name", "ftp_password");

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileStream fs = File.OpenRead(source);
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                fs.Close();

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hata: " + ex.Message.ToString());
               // throw ex;
            }
        }
Merhaba, ben direkt sql serverda bulunan tablodaki resmi ftpye yüklemek istiyorum yardımcı olabilir misiniz
 

Technopat Haberler

Yeni konular

Geri
Yukarı