using Sdaleo; using Sdaleo.Systems.Advantage; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using Yaulw.Assembly; using Yaulw.File; using Yaulw.Registry; namespace quickftp { class Program { public static string DataRet_Retrieve(object o) { if(o != null && !String.IsNullOrEmpty(o.ToString())) { return o.ToString().Trim(); } return ""; } static void Main(string[] args) { string path = quickftp.Properties.Settings.Default.AdvantagePath; string user = quickftp.Properties.Settings.Default.AdvantageUser; string pass = quickftp.Properties.Settings.Default.AdvantagePass; string fpath = AssemblyW.SpecializedAssemblyInfo.GetAssemblyPath(AssemblyW.AssemblyST.Executing); string fname = DateTime.Now.ToShortDateString().Replace('/', '_'); if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(user) || String.IsNullOrEmpty(pass)) { Console.WriteLine("Advantage settings blank or null"); return; } AdvantageCredential cred = new AdvantageCredential(path, user, pass, AdvantageCredential.ServerType.REMOTE_LOCAL); if(!cred.IsValid) { Console.WriteLine("Advantage connection invalid"); return; } string query1 = ReadQuery("query1.txt"); if (String.IsNullOrEmpty(query1)) return; DB db = DB.Create(cred); DBRetVal retVal = db.FillDataTable(query1); if(!retVal.IsValid) { Console.WriteLine(retVal.ErrorMsg); return; } try { DataTable dt = retVal.GetDataTableRetVal(); StringBuilder sbColumns = new StringBuilder(); foreach (DataColumn c in dt.Columns) { sbColumns.Append(c.ColumnName); sbColumns.Append(','); } String columnHeader = sbColumns.ToString().Substring(0, sbColumns.Length - 1); String[] columns = columnHeader.Split(','); FileWriter fw = new FileWriter(fname, "csv", fpath); fw.WriteLineA(columnHeader); foreach (DataRow r in dt.Rows) { StringBuilder sbRow = new StringBuilder(); for (int i = 0; i < columns.Length; ++i) { sbRow.Append(DataRet_Retrieve(r[columns[i]])); sbRow.Append(','); } String rowValues = sbRow.ToString().Substring(0, sbRow.Length - 1); fw.WriteLineA(rowValues); } } catch(Exception e) { Console.WriteLine(e.Message); } SendFileToSFTP(fpath + "\\" + fname + ".csv"); Process.GetCurrentProcess().Close(); } public static string ReadQuery(string filename) { try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader(filename)) { // Read the stream to a string, and write the string to the console. String line = sr.ReadToEnd(); return line; } } catch (Exception e) { Console.WriteLine(String.Format("The file could not be read: {0}", filename)); Console.WriteLine(e.Message); } return ""; } public static void SendFileToSFTP(string fileNameNPath) { string regValue = RegKey.GetKey(HKEYRoot.LocalMachine, "Software\\PanaceanTech", "SMFTP", "").ToLower(); if (!regValue.Contains("d") && !regValue.Contains("i") && !regValue.Contains("c") && !regValue.Contains("k") && !regValue.Contains("s")) { Console.WriteLine("Not Registered - Unlicensed"); return; } using (SMFTP.SFTPClient client = new SMFTP.SFTPClient()) { //bool bConnected = client.Connect("secureftp.navicure.com", "5S3F054P", "LPM2055"); bool bConnected = client.Connect("ftp.eresourceplanner.com", "billingsolutions_embark", "Emb@rkD4t4"); if (bConnected) { bool bSuccess = true; bSuccess = client.CmdExe_MPutFiles(String.Format("\"{0}\"", fileNameNPath)); Console.WriteLine(String.Format("File Send : {0}", bSuccess)); //if (bSuccess) // bSuccess = client.CmdExec_RemoteDirExists("out/997"); //if (bSuccess) // bSuccess = client.CmdExec_LocalDirSet("c:\\out", true); //if (bSuccess) // bSuccess = client.CmdExe_MGetDir(true, "out/997"); //if (bSuccess) // bSuccess = client.CmdExec_RemoteDirSet("in"); //if (bSuccess) // bSuccess = client.CmdExec_LocalDirSet("c:\\out\\997", true); //if (bSuccess) // bSuccess = client.CmdExe_MPutFiles("\"C:\\out\\Doris day\\EmptyDummy File.txt\""); //if (bSuccess) // bSuccess = client.CmdExe_MDelFiles("*.997"); if (bSuccess) File.Delete(fileNameNPath); } } } } }