Example #1
0
        public bool InsertFtpRecord(FileDetail fileDetail)
        {
            var lcsql =
                "insert into MasterFtp(FileName, CreateTime, Folder, Records, DlTime) values ( ?, ?,?,?,?)";


            var connectionString = ConfigurationManager.ConnectionStrings["vfpConnectionString"].ConnectionString;
            using (var connection = new OleDbConnection(connectionString))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SET NULL OFF";

                    command.ExecuteNonQuery();
                }
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = lcsql;
                    command.Parameters.AddWithValue("FileName", fileDetail.FileName);
                    command.Parameters.AddWithValue("CreateTime", fileDetail.FileDate);
                    command.Parameters.AddWithValue("Folder", fileDetail.Folder);
                    command.Parameters.AddWithValue("Records", fileDetail.Records);
                    command.Parameters.AddWithValue("DlTime", fileDetail.DownloadTime);

                    //connection.Open();
                    var retval = command.ExecuteNonQuery();
                    var success = (retval == 1);
                    return success;
                }
            }


        }
Example #2
0
        public bool InsertSqlFtpRecord(FileDetail detail)
        {
            var connString = ConfigurationManager.ConnectionStrings["DatabaseContext"].ConnectionString;
            var sql =
                "insert into MasterFtp(FileName, CreateTime, Folder, Records, DlTime) values ( @fileName, @createTime,@folder,@Records,@dlTime)";
            using (var conn = new SqlConnection())
            {
                conn.ConnectionString = connString;
                conn.Open();
                var cmd = new SqlCommand(sql, conn);
                var p = new SqlParameter
                {
                    ParameterName = "@fileName",
                    DbType = DbType.String,
                    Value = detail.FileName
                };
                cmd.Parameters.Add(p);

                p = new SqlParameter
                {
                    ParameterName = "@createTime",
                    DbType = DbType.DateTime,
                    Value = detail.FileDate
                };
                cmd.Parameters.Add(p);


                p = new SqlParameter
                {
                    ParameterName = "@folder",
                    DbType = DbType.String,
                    Value = detail.Folder
                };
                cmd.Parameters.Add(p);


                p = new SqlParameter
                {
                    ParameterName = "@records",
                    DbType = DbType.Int32,
                    Value = detail.Records
                };
                cmd.Parameters.Add(p);


                p = new SqlParameter
                {
                    ParameterName = "@dlTime",
                    DbType = DbType.DateTime,
                    Value = detail.DownloadTime
                };
                cmd.Parameters.Add(p);

                var retval = cmd.ExecuteNonQuery();
                var success = (retval == 1);
                return success;
            }
        }
Example #3
0
 private static void InsertRecord()
 {
     FileDetail detail = new FileDetail
     {
         DownloadTime = DateTime.Now,
         FileDate = DateTime.Now,
         FileName = "TEST",
         Folder = "TEST",
         Records = 99
     };
     Console.WriteLine($"Inserting {detail.FileName} into master ftp dbf");
     _dbHelper.InsertFtpRecord(detail);
     Console.WriteLine($"Inserting {detail.FileName} into master ftp sql");
     _dbHelper.InsertSqlFtpRecord(detail);
 }
Example #4
0
        private static void GetFtpFiles(Ftpinfo ftpinfo, Ftp ftp, string siteurl)
        {
          
            if (ftpinfo.FileType == DirectoryEntryTypes.Directory)
            {
                var subFiles = ftp.Browse(siteurl + ftpinfo.Filename);
                if (subFiles == null)
                {
                    return;
                }
                foreach (var subFile in subFiles)
                {
                   
                   // Console.WriteLine($"File Name: {subFile.Filename}, File Type: {subFile.FileType}");
                    if (subFile.FileType == DirectoryEntryTypes.Directory)
                    {
                        var path = subFile.Path;
                        if (!path.EndsWith("/"))
                        {
                            path = path + "/";
                        }
                        GetFtpFiles(subFile, ftp, path );
                    }
                    else
                    {
                        var fileTime = subFile.FileDateTime;
                        var kftpfolder = ConfigurationManager.AppSettings["ftpSaveDestination"]; 
                        var fileName = subFile.Filename;
                        var fileDate = fileTime.Date;
                        var arr = subFile.Path.Split('/');
                        var folder = arr[arr.Length-1];
                        var folderFullPath = Path.Combine(kftpfolder, folder, fileDate.ToString("MMddyyyy"));
                        if (!Directory.Exists(folderFullPath))
                        {
                            Directory.CreateDirectory(folderFullPath);
                        }
                        var ftpFileName = Path.Combine(folderFullPath, fileName);
                      //  Console.WriteLine($"Name: {subFile.Filename}\tSize: {subFile.Size}");
                        if (fileTime < new DateTime(2016,1,16) || File.Exists(ftpFileName))
                        {
                           // Console.WriteLine($"{ftpFileName} already exists");
                        }
                        else
                        {
                            Console.WriteLine($"New file found: {fileName}");
                            var path = subFile.Path;
                            if (!path.EndsWith("/"))
                            {
                                path = path + "/";
                            }
                            FtpDownload.Fileinfo fileInfo = new FtpDownload.Fileinfo(path + fileName,ftpFileName,DirectionEnum.Down,true);
                           // ftp.AddFileToDownloadQueue(path + fileName, ftpFileName);
                           // ftp.StartProcessing();
                            ftp.Download(fileInfo);
                            var lineCount = File.ReadLines(ftpFileName).Count();
                            // minus 2 for Header line and blank line after header line

                            FileDetail fileDetail = new FileDetail
                            {
                                FileName = fileName,
                                DownloadTime = DateTime.Now,
                                FileDate = fileTime,
                                Folder = folder,
                                Records = lineCount - 2
                            };
                            _list.Add(fileDetail);
                            //_dbHelper.InsertFtpRecord(fileDetail);
                        }
                    }
                }
            }
        }