static void Main(string[] args) { FtpCredential credential = new FtpCredential(); credential.SetPassword("HelloWorld"); String password = credential.GetPassword(); }
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)); } } } }
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()); } } } }
public FtpCredential Update(FtpCredential cred) { _dbContext.Entry(cred).State = EntityState.Modified; _dbContext.SaveChanges(); return(cred); }
public FtpCredential Add(FtpCredential dto) { dto = _dbContext.FtpCredentials.Add(dto); _dbContext.SaveChanges(); return(dto); }
public bool IsExists(FtpCredential dto) { return(_dbContext .FtpCredentials .Any(cred => !cred.Deleted && (cred.Id == dto.Id || cred.FtpName == dto.FtpName))); }