Example #1
0
        public ActionResult Index(FtpModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var configurations = new Dictionary <string, string>
            {
                { "User", model.User },
                { "Password", model.Password },
                { "Host", model.Host },
                { "Port", model.Port ?? "" }
            };

            var integration = new Integration
            {
                IntegrationSystem = IntegrationSystem.Ftp,
                Name     = model.Name,
                User     = _context.Users.GetByUserName(UserName),
                Settings = configurations
            };

            _context.Integrations.Add(integration);

            _context.SaveChanges();

            return(RedirectToAction("Index", "Integration"));
        }
Example #2
0
        public async Task <List <string> > Query(FtpModel model)
        {
            string uri = "FTP://" + model.ServerIp + "/" + model.DirectoryPath;
            var    ftp = (FtpWebRequest)WebRequest.Create(uri);                      //建立FTP連線

            ftp.Credentials = new NetworkCredential(model.UserName, model.Passwrod); //帳密驗證
            ftp.Timeout     = 2000;                                                  //等待時間
            ftp.UseBinary   = true;                                                  //傳輸資料型別 二進位/文字
            ftp.Method      = WebRequestMethods.Ftp.ListDirectory;                   //取得檔案清單

            var result = new List <string>();

            try
            {
                using (var sr = new StreamReader(ftp.GetResponse().GetResponseStream(), Encoding.UTF8))
                {
                    while (!(sr.EndOfStream))
                    {
                        result.Add(await sr.ReadLineAsync());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Example #3
0
 public FtpService()
 {
     ftpModel = new FtpModel
     {
         FtpUrl      = WebConfigurationManager.AppSettings["ftpUrl"] ?? "",
         FtpPort     = WebConfigurationManager.AppSettings["ftpPort"] ?? "",
         FtpUser     = WebConfigurationManager.AppSettings["ftpUser"] ?? "",
         FtpPwd      = WebConfigurationManager.AppSettings["ftpPwd"] ?? "",
         FtpPath     = WebConfigurationManager.AppSettings["ftpPath"] ?? "",
         FtpFileName = WebConfigurationManager.AppSettings["ftpFileName"] ?? "",
         LocalPath   = WebConfigurationManager.AppSettings["localPath"] ?? "",
     };
 }
Example #4
0
        public async Task <ApiResult <List <string> > > Query(FtpModel model)
        {
            var ftp    = new FtpHelper();
            var result = new ApiResult <List <string> >();

            try
            {
                var query = await ftp.Query(model);

                result.Result = query;
            }
            catch (Exception ex)
            {
                result.Result  = null;
                result.Code    = ResultCode.Error;
                result.Message = ex.Message;
            }

            return(result);
        }