29 Haziran 2016 Çarşamba

FTP ye dosya yükleme FTP Upload

FTP ye dosya yüklemek için kullanacağımız method aşağıdaki gibidir. 

public static Exception FtpUpload(string ftpadresi, string ftpusername, string ftppassword, string localadres, string dosyaadi)
        {
            try
            {
                string wftp = ftpadresi + "/" + dosyaadi;
                string wloc = localadres + "\\" + dosyaadi;
                using (WebClient client = new WebClient())
                {
                    client.Credentials = new NetworkCredential(ftpusername, ftppassword);
                    client.UploadFile(wftp, "STOR", wloc);
                }
                return null;
            }
            catch(Exception ex)
            {
                return ex;
            }
        }

Metodun Kullanımı

if (FtpUpload("ftp://192.168.1.67:3129","xxx","yyy","c:\\deneme","ornek.txt) == null)
{
MessageBox.Show("Başarılı");
}

Hiç yorum yok:

Yorum Gönder