Пример #1
0
 // -----------------------------------------------
 // fayli FTP servere gonderen method... internetden tapdim...
 // methodun axirinda faylin ugurla gonderilib gonderilmediyini oyrenmek ucun responce qaytariram
 // hemin cavabdan asli olaraq bu methodun cagirildigi yerde - SendFileCallback() methodunda fayli Appserverden silirem
 public static FtpWebResponse UploadToFTPServer(this ContentWrapper _content)
 {
     byte[] fileContent = null;
     using (StreamReader sr = new StreamReader(_content.file.FullName))
     {
         fileContent = Encoding.UTF8.GetBytes(sr.ReadToEnd());
     }
     using (Stream sw = _content.FtpRequest.GetRequestStream())
     {
         sw.Write(fileContent, 0, fileContent.Length);
     }
     return((FtpWebResponse)_content.FtpRequest.GetResponse());
 }
Пример #2
0
        // -----------------------------------------------
        public static IEnumerable <ContentWrapper> prepareContentWrapper(FileInfo[] _files)
        {
            foreach (var item in _files)
            {
                ContentWrapper cw = new ContentWrapper();
                cw.file                   = item;
                cw.FtpFoldername          = Path.GetFileNameWithoutExtension(item.FullName);
                cw.FtpRequest             = (FtpWebRequest)WebRequest.Create($"{ConfigurationManager.AppSettings["ftpserver"]}/{cw.FtpFoldername}/{DateTime.Now.ToString("dd-MM-yyyy_hh-mm-ss")}.txt");
                cw.FtpRequest.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["ftpusername"], ConfigurationManager.AppSettings["ftppassword"]);
                cw.FtpRequest.Method      = WebRequestMethods.Ftp.UploadFile;

                yield return(cw);
            }
        }