コード例 #1
0
        static void Main(string[] args)
        {
            FtpCredential credential = new FtpCredential();

            credential.SetPassword("HelloWorld");
            String password = credential.GetPassword();
        }
コード例 #2
0
        public IEnumerable <(string fileName, string accountName, DateTime dateCreation)> LoadFiles(
            FtpCredential ftpCred)
        {
            var ftpUrl = ftpCred.Url;

            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl);

            request.Method = WebRequestMethods.Ftp.ListDirectory;

            request.Credentials = new NetworkCredential(ftpCred.UserName, ftpCred.UserPassword);

            using (var response = (FtpWebResponse)request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        var fileName = "";
                        do
                        {
                            fileName = reader.ReadLine();

                            if (_fileNameMatcher.IsMatch(fileName))
                            {
                                var account = _fileNameMatcher.ParseAccountName(fileName);

                                DateTime?creationDate = null;
                                if (_fileNameMatcher.IsTradeAsReport(fileName))
                                {
                                    creationDate = DateHelper.ParseDate(fileName, 1);
                                }
                                else
                                {
                                    creationDate = DateHelper.ParseDate(fileName);
                                }

                                yield return(fileName, account, creationDate.Value);
                            }
                        } while (!string.IsNullOrEmpty(fileName));
                    }
                }
            }
        }
コード例 #3
0
        public async Task <IEnumerable <(string fileName, string accountName, DateTime creationDate)> > LoadFilesAsync(FtpCredential ftpCred)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpCred.Url);

            request.Method = WebRequestMethods.Ftp.ListDirectory;

            request.Credentials = new NetworkCredential(ftpCred.UserName, ftpCred.UserPassword);

            using (var response = (FtpWebResponse)await request.GetResponseAsync())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    var resultList = new HashSet <(string, string, DateTime)>();

                    using (var reader = new StreamReader(responseStream))
                    {
                        var fileName = "";
                        do
                        {
                            fileName = reader.ReadLine();

                            if (_fileNameMatcher.IsMatch(fileName))
                            {
                                var account = _fileNameMatcher.ParseAccountName(fileName);

                                DateTime?creationDate = null;
                                if (_fileNameMatcher.IsTradeAsReport(fileName))
                                {
                                    creationDate = DateHelper.ParseDate(fileName, 1);
                                }
                                else
                                {
                                    creationDate = DateHelper.ParseDate(fileName);
                                }

                                resultList.Add((fileName, account, creationDate.Value));
                            }
                        } while (!string.IsNullOrEmpty(fileName));

                        return(resultList.ToList());
                    }
                }
            }
        }
コード例 #4
0
 public FtpCredential Update(FtpCredential cred)
 {
     _dbContext.Entry(cred).State = EntityState.Modified;
     _dbContext.SaveChanges();
     return(cred);
 }
コード例 #5
0
 public FtpCredential Add(FtpCredential dto)
 {
     dto = _dbContext.FtpCredentials.Add(dto);
     _dbContext.SaveChanges();
     return(dto);
 }
コード例 #6
0
 public bool IsExists(FtpCredential dto)
 {
     return(_dbContext
            .FtpCredentials
            .Any(cred => !cred.Deleted && (cred.Id == dto.Id || cred.FtpName == dto.FtpName)));
 }