internal SftpStreamChilkat(Chilkat.SFtp sftp, string remoteFileName) { _sftp = sftp; _currentPos = 0; _remoteFileName = remoteFileName; _handle = _sftp.OpenFile(_remoteFileName, "readOnly", "openExisting"); if (_handle == null) { throw new IOException("Cannot open " + remoteFileName); } }
static Chilkat.SFtp initSftp() { Chilkat.SFtp sftp = new Chilkat.SFtp(); bool success = sftp.UnlockComponent("Anything for 30-day trial"); if (success != true) { Console.WriteLine(sftp.LastErrorText); } sftp.ConnectTimeoutMs = 10000; sftp.IdleTimeoutMs = 10000; // Connect to the SSH server. // The standard SSH port = 22 // The hostname may be a hostname or IP address. int port; string hostname; hostname = "sftp1.wallst.com"; port = 22; success = sftp.Connect(hostname, port); if (success != true) { Console.WriteLine(sftp.LastErrorText); return(sftp); } // Authenticate with the SSH server. Chilkat SFTP supports // both password-based authenication as well as public-key // authentication. This example uses password authenication. success = sftp.AuthenticatePw("BLRK-LON-DTC-DS", "n19!y!7AcTaP"); if (success != true) { Console.WriteLine(sftp.LastErrorText); return(sftp); } // After authenticating, the SFTP subsystem must be initialized: success = sftp.InitializeSftp(); if (success != true) { Console.WriteLine(sftp.LastErrorText); return(sftp); } return(sftp); }
static void MovefileToEmpty(Chilkat.SFtp sftp, string fileName) { Console.WriteLine("path is {0}", AppDomain.CurrentDomain.BaseDirectory); string remoteFilePath = "/Incoming/FromETP/History/" + fileName; string newRemoteFilePath = "/Incoming/FromETP/History/Empty/" + fileName; string localfilePath = AppDomain.CurrentDomain.BaseDirectory + fileName; bool success; success = sftp.DownloadFileByName(remoteFilePath, localfilePath); if (success != true) { Console.WriteLine(sftp.LastErrorText); } success = sftp.UploadFileByName(newRemoteFilePath, localfilePath); if (success != true) { Console.WriteLine(sftp.LastErrorText); } DeleteLocal(localfilePath); }
static void SendFile() { Chilkat.SFtp ftpclient = new Chilkat.SFtp(); bool isUnlocked = ftpclient.UnlockComponent("SCOTTGFTP_bsex2TmE3Znh"); ftpclient.HttpProxyHostname = System.Configuration .ConfigurationManager.AppSettings["FTPServer"]; ftpclient.HttpProxyPort = int.Parse(System.Configuration .ConfigurationManager.AppSettings["FTPPort"]); ftpclient.HttpProxyUsername = System.Configuration .ConfigurationManager.AppSettings["FTPID"]; ftpclient.HttpProxyPassword = System.Configuration .ConfigurationManager.AppSettings["FTPPWD"]; Chilkat.SFtp sftp = new Chilkat.SFtp(); bool success = sftp.UnlockComponent("SCOTTGSSH_ybO3Nkv30PxT"); if (success != true) { Console.WriteLine(sftp.LastErrorText); return; } sftp.ConnectTimeoutMs = 15000; sftp.IdleTimeoutMs = 15000; int port; string hostname; hostname = "74.118.41.43"; port = 12639; success = sftp.Connect(hostname, port); if (success != true) { Console.WriteLine(sftp.LastErrorText); return; } success = sftp.AuthenticatePw("connortho", "D5ZdCYKW"); if (success != true) { Console.WriteLine(sftp.LastErrorText); return; } success = sftp.InitializeSftp(); if (success != true) { Console.WriteLine(sftp.LastErrorText); return; } string remoteFilePath = fileName; string localFilePath = filePath + fileName; success = sftp.UploadFileByName(remoteFilePath, localFilePath); if (success != true) { Console.WriteLine(sftp.LastErrorText); return; } Console.WriteLine("Success."); }
public string uploadImage(string path, string fileName) { Chilkat.SFtp sftp = new Chilkat.SFtp(); bool success; success = sftp.UnlockComponent("Anything for 30-day trial"); if (success != true) { MessageBox.Show(sftp.LastErrorText); return null; } sftp.ConnectTimeoutMs = 5000; sftp.IdleTimeoutMs = 10000; success = sftp.Connect("http://kdspykim2.cafe24.com", 22); if (success != true) { MessageBox.Show(sftp.LastErrorText); return null; } success = sftp.AuthenticatePw("image", "dlalwlfmfsjgdjfk"); if (success != true) { MessageBox.Show(sftp.LastErrorText); return null; } success = sftp.InitializeSftp(); if (success != true) { MessageBox.Show(sftp.LastErrorText); return null; } string uploadFileName = makeFileName(fileName); string handle; handle = sftp.OpenFile("public_html/" + uploadFileName, "writeOnly", "createTruncate"); if (handle == null) { MessageBox.Show(sftp.LastErrorText); return null; } success = sftp.UploadFile(handle, path); if (success != true) { MessageBox.Show(sftp.LastErrorText); return null; } success = sftp.CloseHandle(handle); if (success != true) { MessageBox.Show(sftp.LastErrorText); return null; } return uploadFileName; }
static List <string> GetFileNamesInFtp(List <string> theseDates) { Dictionary <string, int> FilesAndSizes = new Dictionary <string, int>(); List <string> result = new List <string>(); List <Chilkat.SFtpFile> files = new List <Chilkat.SFtpFile>(); Chilkat.SFtp sftp = initSftp(); bool success; // Open a directory on the server... // Paths starting with a slash are "absolute", and are relative // to the root of the file system. Names starting with any other // character are relative to the user's default directory (home directory). // A path component of ".." refers to the parent directory, // and "." refers to the current directory. string handle; //handle = sftp.OpenDir("/Incoming/FromETP/History"); handle = sftp.OpenDir("/Incoming/FromETP/AdditionalHistoryBenchmark"); if (sftp.LastMethodSuccess != true) { Console.WriteLine(sftp.LastErrorText); return(result); } // Download the directory listing: Chilkat.SFtpDir dirListing = null; dirListing = sftp.ReadDir(handle); if (sftp.LastMethodSuccess != true) { Console.WriteLine(sftp.LastErrorText); return(result); } int i; int n = dirListing.NumFilesAndDirs; if (n == 0) { Console.WriteLine("No entries found in this directory."); } else { int count = 0; for (i = 0; i <= n - 1; i++) { Chilkat.SFtpFile fileObj = null; fileObj = dirListing.GetFileObject(i); FilesAndSizes.Add(fileObj.Filename, fileObj.Size32); files.Add(fileObj); count = i; } Console.WriteLine("found {0} Candidate files", count); count = 0; foreach (string date in theseDates) { int trytimes = 0; string searchDate = date; string sFileName = String.Empty; do { trytimes++; if (trytimes > 10) { log("Error, didn't find for " + searchDate); break; // didn't find one for this month } var Ifiles = FilesAndSizes.Where(pv => pv.Key.Contains(searchDate)).Select(pv => pv.Key); if (Ifiles.Count() == 0) { searchDate = PreviousDay(searchDate); continue; } if (Ifiles.Count() > 1) { throw new Exception("more than one file found"); } sFileName = Ifiles.FirstOrDefault(); if (FilesAndSizes[sFileName] < 4000) { searchDate = PreviousDay(searchDate); sFileName = String.Empty; continue; } result.Add(sFileName); count++; }while(sFileName == String.Empty); } Console.WriteLine("found {0} files", count); } // Close the directory success = sftp.CloseHandle(handle); if (success != true) { Console.WriteLine(sftp.LastErrorText); return(result); } Console.WriteLine("Success."); sftp.Disconnect(); return(result); }
static void Main(string[] args) { Console.WriteLine("do you want to move files on production FTP?"); Console.ReadLine(); Console.WriteLine("are you sure"); Console.ReadLine(); //Chilkat.SFtp sftp = new Chilkat.SFtp(); // Movefile(initSftp()); // PrintFileNamesInFtp(); int count = 0; List <string> lLastDays = GetLastTradeDayOfMonth(); List <string> lFiles = GetFileNamesInFtp(lLastDays); foreach (string file in lFiles) { Console.WriteLine("move {0}", file); MovefileToLastDayOfMonth(initSftp(), file); log("success, moved file " + file); count++; } System.IO.File.WriteAllText(Environment.CurrentDirectory + @"\log.txt", sLog); Console.WriteLine("returned {0} dates", count); Chilkat.SFtp sftp = initSftp(); //Console.WriteLine("the current directory is {0}", Environment.CurrentDirectory); Console.ReadLine(); Environment.Exit(0); System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start(); DAGScript ds = new DAGScript(); ds.run(); timer.Stop(); TimeSpan ts = timer.Elapsed; Console.WriteLine("processed file in {0} time", String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds)); Console.ReadLine(); Environment.Exit(0); var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { DataCreator dc = new DataCreator(); int[] col = new int[] { 19, 20, 410, 458 }; dc.WriteHistoryFile(@"C:\Projects\Playground\Eric.Scott\TextfileValidator\bin\Debug", "BR_History", "txt", @"C:\Projects\Playground\Eric.Scott\TextfileValidator\bin\Debug", "mkt_ETF_Analytics_Data", "txt", 400, col, null); Console.WriteLine("first was {0}", options.SampleDataGenArgs[0]); Console.ReadLine(); Environment.Exit(0); } Environment.Exit(0); // CreateDatesAndFileNames(10); string baseFileName = @"C:\Projects\Playground\Eric.Scott\TextfileValidator\bin\Debug\BR_History.txt"; string ISIN = "GB00B15KY328"; //string targetFileName = GetTargetFileName(1); DateTime asOfDate = DateTime.Now; CreateFirstHistoryFile(baseFileName, ISIN, DateAndFileNames.Last().Value, DateAndFileNames.Last().Key); for (int i = DateAndFileNames.Count - 1; i > 0; i--) { CreateFirstHistoryFile(DateAndFileNames.ElementAt(i).Value, ISIN, DateAndFileNames.ElementAt(i - 1).Value, DateAndFileNames.ElementAt(i - 1).Key); Console.WriteLine("Created File {0} for Date: {1}", DateAndFileNames.ElementAt(i - 1).Value, DateAndFileNames.ElementAt(i - 1).Key); } Console.ReadLine(); }