コード例 #1
0
        /// <summary>
        /// Deleting file from ftp
        /// </summary>
        /// <param name="con">Connection class exemplar</param>
        /// <param name="fullFileName">Full file name (path + name) on FTP.
        /// Example: "ftp://ftpex.e-vo.ru/outbox/Test.xml"</param>
        /// <returns>Exception text.
        /// If there is no ex, will return an empty string.</returns>
        public bool DeleteFileFromFtp(Ftp_Connection con, string fullFileName, ref string exceptionText)
        {
            exceptionText = "";
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(fullFileName);

            request.Credentials = new NetworkCredential(con.UserName, con.Password);
            request.Method      = WebRequestMethods.Ftp.DeleteFile;
            try { request.Method = WebRequestMethods.Ftp.DeleteFile; }
            catch (Exception ex) { exceptionText = "Ошибка!\n" + ex.Message + "\nНе удалось произвести удаление файла " + fullFileName; return(false); }
            return(true);
        }
コード例 #2
0
 /// <summary>
 /// Uploading file to FTP
 /// </summary>
 /// <param name="con">Connection class exemplar</param>
 /// <param name="ftpPath">FTP path
 /// Example: "ftp://ftpex.e-vo.ru/outbox/"</param>
 /// <param name="fileName">Name of the uploading file
 /// Examole: Test.xml</param>
 /// <returns>Exception text
 /// If there is no ex, will return an empty string</returns>
 public bool UploadToFTP(Ftp_Connection con, string fileName, ref string exceptionText)
 {
     exceptionText = "";
     using (WebClient client = new WebClient())
     {
         try
         {
             client.Credentials = new NetworkCredential(con.UserName, con.Password);
             client.UploadFile(con.FtpOut + fileName, con.DwnldFlsPth + fileName);
         }
         catch (Exception ex) { exceptionText = ex.Message; return(false); }
     }
     return(true);
 }
コード例 #3
0
        /// <summary>
        /// Receiving order from FTP by order file name
        /// </summary>
        /// <param name="con">Connection class exemplar</param>
        /// <param name="docName">document name file name
        /// Example: order_20180621124445_2212524051.xml</param>
        /// <returns>Is download complee succsessfully</returns>
        public bool DownloadFile(Ftp_Connection con, string docName, ref string exceptionText)
        {
            exceptionText = "";
            WebClient request = new WebClient();

            request.Credentials = new NetworkCredential(con.UserName, con.Password);
            try { request.DownloadFile(con.FtpIn + docName, con.DwnldFlsPth + docName); }
            catch (Exception ex)
            {
                exceptionText = ex.Message + " Не удалось записать файл " + con.FtpIn + docName + " по адресу " + con.DwnldFlsPth + docName + "!";
                return(false);
            }
            request.Dispose();
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Receiving orders list method
        /// </summary>
        /// <param name="con">FTP-Connection class exemplar</param>
        /// <returns>OrderList class exemplar</returns>
        public OrderList GetOrderList(Ftp_Connection con, string searchFilesTemplate)
        {
            OrderList     orderList = new OrderList();
            FtpWebRequest request   = (FtpWebRequest)WebRequest.Create(con.FtpIn);

            request.Method      = WebRequestMethods.Ftp.ListDirectory;
            request.Credentials = new NetworkCredential(con.UserName, con.Password);
            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        if (line.Contains((searchFilesTemplate == "") ? Param.EXITE_ORDER_ID : searchFilesTemplate))
                        {
                            orderList.List.Add(line);
                        }
                    }
            return(orderList);
        }
コード例 #5
0
        /// <summary>
        /// Receiving all orders from FTP by order list
        /// </summary>
        /// <param name="con">Connection class exemplar</param>
        /// <param name="list">Orders list</param>
        /// <param name="exceptionText">linked exception variable</param>
        /// <returns>Is download complee succsessfully</returns>
        public bool DownloadAllFiles(Ftp_Connection con, OrderList list, ref string exceptionText)
        {
            if (list.List.Count == 0)
            {
                return(true);
            }
            exceptionText = "";
            WebClient request = new WebClient();

            request.Credentials = new NetworkCredential(con.UserName, con.Password);
            for (int i = 0; i < list.List.Count; i++)
            {
                string filename = list.GetListElement(i);
                try { request.DownloadFile(con.FtpIn + filename, con.DwnldFlsPth + filename); }
                catch (Exception ex)
                {
                    exceptionText = ex + "\nНе удалось записать файл " + con.FtpIn + filename + " по адресу " + con.DwnldFlsPth + filename + "!";
                    return(false);
                }
            }
            request.Dispose();
            return(true);
        }