public bool GetFiles() { bool status = true; Sftp sftp = new Sftp( m_sftpSite, m_sftpSiteUserName ); try { // add our private key to connect // put these in the config file sftp.AddIdentityFile(@"d:\apps\RSAKeys\opensshkey"); // connect sftp.Connect(); // get a directory list ArrayList rFiles = sftp.GetFileList( m_sftpSiteRemoteFolder ); foreach ( string file in rFiles ) { if (file.Equals(".") || file.Equals("..")) continue; // get the file and put in the watch folder to be processed sftp.Get(m_sftpSiteRemoteFolder + file, m_moveToProcessFolder + file); // update our database that we have downloaded the file from the server // this.updateDb( file ); // delete the file on the remote server after pulling it over // sftp.Delete(f); } sftp.Close(); status = true; } catch (Tamir.SharpSsh.jsch.SftpException se) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + se.Message); } catch (Tamir.SharpSsh.jsch.JSchException jse) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + jse.Message); } catch (Tamir.SharpSsh.SshTransferException ste) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + ste.Message); } catch (SystemException se) { LogMsg("NEXCEPTION:SftpMgr::GetFile():ECaught:" + se.Message); } return status; }
static void Main(string[] args) { Sftp sftp = new Sftp("10.5.1.108", "developer", "pandora"); //sftp.AddIdentityFile("[Path to Private kEY]"); sftp.Connect(); //sftp.Put(@"D:\temp\blog\feed.csv", "[PATH OF FILE ON SERVER]"); //sftp.Delete("[PATH OF FILE ON SERVER]"); Console.WriteLine(String.Join("\n", sftp.GetFileList("Desktop"))); foreach (long size in sftp.GetFileSizes("Desktop")) { Console.WriteLine(Convert.ToString(size)); } sftp.Close(); }
public static bool image_01_FileMake(string filePath) { Boolean bResult; string _sftpHost = "ledev.leisureq.co.kr"; string _sftpUserId = "lion"; string _sftpUserPw = "gkffl1!"; Int32 _sftpPort = 10004; string[] path = filePath.Split(new char[] { '/' }); try { string ppath = ""; Sftp sftp = new Tamir.SharpSsh.Sftp(_sftpHost, _sftpUserId, _sftpUserPw); sftp.Connect(_sftpPort); for (int i = 1; i < path.Length; i++) { ppath = ppath + "/" + path[i]; ArrayList res = sftp.GetFileList(ppath); string checkFile = path[i+1]; if (res.IndexOf(checkFile) == -1) { sftp.Mkdir(ppath + "/" + checkFile); } } bResult = true; } catch (SystemException ex) { NewLogManager2.Instance.Log(string.Format("Error image_01_FileMake {0}", ex.Message)); bResult = false; } return bResult; }
public static bool image_01_FileMake(string filePath) { Boolean bResult; string _sftpHost = "ledev.leisureq.co.kr"; string _sftpUserId = "lion"; string _sftpUserPw = "gkffl1!"; Int32 _sftpPort = 10004; string[] path = filePath.Split(new char[] { '/' }); try { string ppath = ""; Sftp sftp = new Tamir.SharpSsh.Sftp(_sftpHost, _sftpUserId, _sftpUserPw); sftp.Connect(_sftpPort); for (int i = 1; i < path.Length; i++) { ppath = ppath + "/" + path[i]; ArrayList res = sftp.GetFileList(ppath); string checkFile = path[i + 1]; if (res.IndexOf(checkFile) == -1) { sftp.Mkdir(ppath + "/" + checkFile); } } bResult = true; } catch (SystemException ex) { NewLogManager2.Instance.Log(string.Format("Error image_01_FileMake {0}", ex.Message)); bResult = false; } return(bResult); }
private void button1_Click(object sender, EventArgs e) { string makefile = HKLibrary.UTIL.HKFileHelper.GetCurrentDirectory(); string sDirPath; sDirPath = makefile + "\\data"; DirectoryInfo di = new DirectoryInfo(sDirPath); if (di.Exists == false) { di.Create(); } string PinCode = "41302903000002"; makefile = makefile + "\\data\\" + PinCode + ".png"; Int32 OrderSeq = 406359; string folderName = Convert.ToString(OrderSeq); string ftpfileName = folderName + "/" + PinCode + ".jpg"; string ftpBasicPath = "/var/www/IMAGE/Web/upload/order/barcode"; //string ftpBasicPath = "/var/www/IMAGE/Web/upload/order/qrcode/"; QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode = qrEncoder.Encode(PinCode); var renderer = new GraphicsRenderer(new FixedCodeSize(400, QuietZoneModules.Zero), Brushes.Black, Brushes.White); MemoryStream ms = new MemoryStream(); renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms); var image = new Bitmap(Image.FromStream(ms), new Size(new Point(200, 200))); image.Save(makefile, ImageFormat.Png); Tamir.SharpSsh.Sftp sftp; sftp = new Tamir.SharpSsh.Sftp("ledev.leisureq.co.kr", "lion", "gkffl1!"); sftp.Connect(10004); ArrayList res = sftp.GetFileList("/"); sftp.Mkdir(ftpBasicPath + "/" + folderName + "/"); sftp.Put(makefile, ftpBasicPath + "/" + ftpfileName); sftp.Close(); //BarcodeLib.Barcode b = new BarcodeLib.Barcode(); //b.Encode(BarcodeLib.TYPE.CODE128, PinCode); //b.SaveImage(makefile, BarcodeLib.SaveTypes.JPG); /* * string date = "2015-05-20 17:16:44"; * string[] datePartPath = new string[4]; * * DateTime dt = Convert.ToDateTime(date); * datePartPath[0] = dt.ToString("yyyy"); * datePartPath[1] = dt.ToString("MM"); * datePartPath[2] = dt.ToString("dd"); * datePartPath[3] = Convert.ToString(OrderSeq); * * * for(Int32 i =0; i<datePartPath.Length; i++){ * ftpBasicPath = ftpBasicPath + "/" + datePartPath[i]; * } * comwls.image_01_FileMake(ftpBasicPath); * */ string ftpUri = "sftp://ledev.leisureq.co.kr:10004/" + ftpBasicPath + folderName; HKLibrary.comwls.comwls.image_01_FileMake(ftpBasicPath + folderName); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri); request.Method = WebRequestMethods.Ftp.MakeDirectory; //request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("lion", "gkffl1!"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream ftpStream = response.GetResponseStream(); ftpStream.Close(); response.Close(); /* * string ftpUri = "ftp://121.78.127.40:21/" + ftpBasicPath + folderName; * * FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri); * request.Method = WebRequestMethods.Ftp.MakeDirectory; * * // This example assumes the FTP site uses anonymous logon. * request.Credentials = new NetworkCredential("infobay", "info9887"); * FtpWebResponse response = (FtpWebResponse)request.GetResponse(); * Stream ftpStream = response.GetResponseStream(); * * ftpStream.Close(); * response.Close(); * * ftpUri = "ftp://121.78.127.40:21/" + ftpBasicPath + ftpfileName; * request = (FtpWebRequest)WebRequest.Create(ftpUri); * request.Method = WebRequestMethods.Ftp.UploadFile; * * // This example assumes the FTP site uses anonymous logon. * request.Credentials = new NetworkCredential("infobay", "info9887"); * * byte[] fileContents = File.ReadAllBytes(makefile); * request.ContentLength = fileContents.Length; * * request.UsePassive = true; * Stream requestStream = request.GetRequestStream(); * requestStream.Write(fileContents, 0, fileContents.Length); * requestStream.Close(); * response = (FtpWebResponse)request.GetResponse(); * response.Close(); * * * * //sftp.ConnectTimeoutMs = 15000; * //sftp.IdleTimeoutMs = 15000; * * //string hostname = "ftp://ledev.leisureq.co.kr:10004/"; * * //bool success = sftp.Connect(hostname, 10004); */ }
private bool GetFiles() { bool status = true; Sftp sftp = new Sftp( m_sftpSite, m_sftpSiteUserName ); try { // add our private key to connect // put these in the config file sftp.AddIdentityFile( m_identityFile ); // connect sftp.Connect(); // get a directory list ArrayList rFiles = sftp.GetFileList( m_sftpSiteRemoteFolder ); int indx = 0; foreach ( string file in rFiles ) { indx++; if (file.Equals(".") || file.Equals("..")) continue; if ( this.CheckDb(file) ) continue; try { // get the file and put in the watch folder to be processed sftp.Get(m_sftpSiteRemoteFolder + file, m_moveToProcessFolder + file); // update the database to indicate file has been downloaded this.UpdateDb(file); // delete the file on the remote server after pulling it over // sftp.Delete(f); } catch (SystemException se) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:TryingToGetFile:" + indx + ":" + file + "::" + se.Message); } } sftp.Close(); status = true; } catch (Tamir.SharpSsh.jsch.SftpException se) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + se.Message); } catch (Tamir.SharpSsh.jsch.JSchException jse) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + jse.Message); } catch (Tamir.SharpSsh.SshTransferException ste) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + ste.Message); } catch (SystemException se) { LogMsg("NEXCEPTION:AMSSftpMgr::GetFile():ECaught:" + se.Message); } return status; }
//Connects to the FTP server and request the list of available files public static List<String> getSecureFileList(Uri FTPAddress, string username, string password, bool UseSSL) { List<String> files = new List<String>(); //string temp = "208.109.47.128"; //"/home/content/74/9833874/html/_RBC/" //Use the URI object to separate the address from the subfolders //Create sFTP request Sftp sftp = new Sftp(FTPAddress.Host, username, password); if (sftp == null) { //Error connecting to FTP server throw new WebException("ERROR - " + ClassName + ": Error connecting to FTP server", WebExceptionStatus.SecureChannelFailure); } else { try { sftp.Connect(); //the foldername cannot be empty, or the listing will not show ArrayList fileList = sftp.GetFileList(FTPAddress.AbsolutePath); foreach (var item in fileList) { if (item.ToString() != "." && item.ToString() != "..") //Console.WriteLine(item.ToString()); files.Add(item.ToString()); } } catch (Tamir.SharpSsh.jsch.SftpException sfex) { // write to log - note the lowercase m in message - this library uses nonstandard error reporting Trace.TraceInformation("ERROR - " + ClassName + ":" + sfex.message); throw new WebException("ERROR - " + ClassName + ": " + sfex.message); } catch (Exception ex) { // write to log Trace.TraceInformation("ERROR - " + ClassName + ": " + ex.Message); //EventLog.WriteEntry(Application.ProductName, "ERROR - " + ClassName + ": " + ex.Message, EventLogEntryType.Error); throw new WebException("ERROR - " + ClassName + ": " + ex.Message); } finally { sftp.Close(); } } return files; }
public void ssh_command(string type, string host, string user, string password, string command) { if (type == "list dir") { Sftp sftp = new Sftp(host, user, password); try { sftp.Connect(); ArrayList analyses = sftp.GetFileList(command); if (analyses.Count > 0) { foreach (string run in analyses) { if (run.Length > 10) { this.stdRunsList.Items.Add(run); } } count_label.Text = "Count: " + stdRunsList.Items.Count.ToString(); connected(); } } catch { ConnectionError.Visible = true; pwdBox.ResetText(); } finally { sftp.Close(); } } else if (type == "kill") { ssh.Write(command); terminalThread.CancelAsync(); } else { try { ssh = new SshStream(host, user, password); abort = false; stopWatch.Start(); terminalThread.RunWorkerAsync(); checkThread.RunWorkerAsync(); ssh.Write(command); } catch (Exception ex) { MessageBox.Show(ex.Message, "Minion - Stream Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button3_Click(object sender, EventArgs e) { if (theFiles == null) { MessageBox.Show("Please select a folder"); return; } WebClient wc = new WebClient(); wc.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); Dictionary<string, string> serverVer = new Dictionary<string, string>(); wc.Proxy = null; try { string toparse = wc.DownloadString(hashesLoc); using (StringReader sr = new StringReader(toparse)) { string thisLine; while ((thisLine = sr.ReadLine()) != null) { if (thisLine.Contains('|')) { string[] splitted = thisLine.Split('|'); serverVer.Add(splitted[0], splitted[1]); } } } } catch (Exception ex) { //MessageBox.Show("Error parsing website, " + ex); //return; Console.WriteLine("Error parsing website, will overwrite everything."); } using (StreamWriter fs = new StreamWriter("hashes.html", false)) { foreach (var s in theFiles) { fs.WriteLine(s.Key + "|" + s.Value); } } var sftp = new Sftp(hostName.Text, User.Text, pass.Text); sftp.OnTransferProgress += new FileTransferEvent(sftp_OnTransferProgress); sftp.Connect(); foreach (var file in theFiles) { if (serverVer.ContainsKey(file.Key)) { if (serverVer[file.Key] == file.Value) { Console.WriteLine("skipped " + file.Key); continue; } } if (file.Key.Contains('\\')) { //FileInfo fi = new FileInfo(dirToHash + "\\" + file.Key); //file.Key.Split(""); string[] splitted = file.Key.Split('\\'); string dirr = root; for (int i = 0; i < splitted.Length - 1; i++) { dirr += splitted[i] + "/"; bool mkdir = false; try { sftp.GetFileList(dirr); } catch (Exception) { mkdir = true; Console.WriteLine("Making directory " + dirr); } if (mkdir) { try { sftp.Mkdir(dirr); } catch (Exception exc) { Console.WriteLine("exception with " + dirr + " while making the dir " + exc); } } } } string changed = file.Key.Replace('\\', '/'); sftp.Put(dirToHash + "\\" + file.Key, root + changed); Console.WriteLine("Sent {0} to {1}", dirToHash + "\\" + file.Key, root + changed); } sftp.Put("hashes.html", root + "hashes.html"); Console.WriteLine("Send hashes.html"); // foreach (string s in sftp.GetFileList("/")) // { // Console.WriteLine(s); // } // sftp. // sftp.Put("test.html","/var/www/test.html"); sftp.Close(); /* FtpWebRequest fRequest = (FtpWebRequest)WebRequest.Create("ftp://proxima-centauri.dreamhost.com/"); //fRequest.Method = WebRequestMethods.Ftp Ftp fRequest.Credentials = new NetworkCredential("aevv", "matteh11F"); Stream ftpStream = fRequest.GetRequestStream(); */ }
private void button1_Click(object sender, EventArgs e) { string makefile = HKLibrary.UTIL.HKFileHelper.GetCurrentDirectory(); string sDirPath; sDirPath = makefile + "\\data"; DirectoryInfo di = new DirectoryInfo(sDirPath); if (di.Exists == false) { di.Create(); } string PinCode = "41302903000002"; makefile = makefile + "\\data\\"+PinCode+".png"; Int32 OrderSeq = 406359; string folderName = Convert.ToString(OrderSeq); string ftpfileName = folderName + "/" + PinCode + ".jpg"; string ftpBasicPath = "/var/www/IMAGE/Web/upload/order/barcode"; //string ftpBasicPath = "/var/www/IMAGE/Web/upload/order/qrcode/"; QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode = qrEncoder.Encode(PinCode); var renderer = new GraphicsRenderer(new FixedCodeSize(400, QuietZoneModules.Zero), Brushes.Black, Brushes.White); MemoryStream ms = new MemoryStream(); renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms); var image = new Bitmap(Image.FromStream(ms), new Size(new Point(200, 200))); image.Save(makefile, ImageFormat.Png); Tamir.SharpSsh.Sftp sftp; sftp = new Tamir.SharpSsh.Sftp("ledev.leisureq.co.kr", "lion", "gkffl1!"); sftp.Connect(10004); ArrayList res = sftp.GetFileList("/"); sftp.Mkdir(ftpBasicPath + "/" + folderName+ "/"); sftp.Put(makefile, ftpBasicPath + "/" + ftpfileName); sftp.Close(); //BarcodeLib.Barcode b = new BarcodeLib.Barcode(); //b.Encode(BarcodeLib.TYPE.CODE128, PinCode); //b.SaveImage(makefile, BarcodeLib.SaveTypes.JPG); /* string date = "2015-05-20 17:16:44"; string[] datePartPath = new string[4]; DateTime dt = Convert.ToDateTime(date); datePartPath[0] = dt.ToString("yyyy"); datePartPath[1] = dt.ToString("MM"); datePartPath[2] = dt.ToString("dd"); datePartPath[3] = Convert.ToString(OrderSeq); for(Int32 i =0; i<datePartPath.Length; i++){ ftpBasicPath = ftpBasicPath + "/" + datePartPath[i]; } comwls.image_01_FileMake(ftpBasicPath); */ string ftpUri = "sftp://ledev.leisureq.co.kr:10004/"+ ftpBasicPath + folderName; HKLibrary.comwls.comwls.image_01_FileMake(ftpBasicPath + folderName); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri); request.Method = WebRequestMethods.Ftp.MakeDirectory; //request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("lion", "gkffl1!"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream ftpStream = response.GetResponseStream(); ftpStream.Close(); response.Close(); /* string ftpUri = "ftp://121.78.127.40:21/" + ftpBasicPath + folderName; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUri); request.Method = WebRequestMethods.Ftp.MakeDirectory; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("infobay", "info9887"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream ftpStream = response.GetResponseStream(); ftpStream.Close(); response.Close(); ftpUri = "ftp://121.78.127.40:21/" + ftpBasicPath + ftpfileName; request = (FtpWebRequest)WebRequest.Create(ftpUri); request.Method = WebRequestMethods.Ftp.UploadFile; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("infobay", "info9887"); byte[] fileContents = File.ReadAllBytes(makefile); request.ContentLength = fileContents.Length; request.UsePassive = true; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); response = (FtpWebResponse)request.GetResponse(); response.Close(); //sftp.ConnectTimeoutMs = 15000; //sftp.IdleTimeoutMs = 15000; //string hostname = "ftp://ledev.leisureq.co.kr:10004/"; //bool success = sftp.Connect(hostname, 10004); */ }