// constructor public SadistaFunctions(string ipAddress, string username, string password, string ssh_host_key_fingerprint) { this.ipAddress = ipAddress; this.username = username; this.password = password; this.ssh_host_key_fingerprint = ssh_host_key_fingerprint; this.session = null; this.sessionOptions = null; }
private void button_Click(object sender, RoutedEventArgs e) { WinSCP.SessionOptions sessionOptions = new WinSCP.SessionOptions(); sessionOptions.HostName = ""; sessionOptions.Password = ""; sessionOptions.PortNumber = 22; List<object> objList = new List<object>(); int[] bacon = new int[5] { 0, 1, 2, 3, 4 }; foreach (var item in bacon) { objList.Add(new object()); MessageBox.Show(objList[0].GetType().ToString()); } }
private bool connect() { try { this.sessionOptions = new WinSCP.SessionOptions { Protocol = WinSCP.Protocol.Sftp, PortNumber = 8888, HostName = this.ipAddress, UserName = this.username, Password = this.password, SshHostKeyFingerprint = this.ssh_host_key_fingerprint }; this.session = new WinSCP.Session(); this.session.Open(this.sessionOptions); return(true); } catch (Exception) { return(false); } }
public SessionOptions() { this.sessionOptions = new WinSCP.SessionOptions(); this.sessionOptions.FtpMode = WinSCP.FtpMode.Passive; try { this.LoadIni(); this.sessionOptions.FtpMode = WinSCP.FtpMode.Passive; this.sessionOptions.HostName = this.iniFile.Read("HOST", "SSH"); this.sessionOptions.UserName = this.iniFile.Read("USERNAME", "SSH"); this.sessionOptions.SshHostKeyFingerprint = this.iniFile.Read("HOST_KEY", "SSH"); this.sessionOptions.SshPrivateKeyPath = this.iniFile.Read("SSH_PRIVATE_KEY_PATH", "SSH"); this.sessionOptions.PrivateKeyPassphrase = this.iniFile.Read("SSH_KEY_PASSWORD", "SSH"); } catch (Exception exception) { Console.WriteLine("Failed connection: " + exception.Message); Console.Read(); } }
private bool UploadToFtp(string filename) { try { var sessionOptions = new WinSCP.SessionOptions { FtpSecure = WinSCP.FtpSecure.None, Protocol = WinSCP.Protocol.Ftp, HostName = ConfigurationManager.AppSettings["FTPHost"], PortNumber = int.Parse(ConfigurationManager.AppSettings["FTPPort"]), UserName = ConfigurationManager.AppSettings["FTPUsername"], Password = ConfigurationManager.AppSettings["FTPPassword"], }; string ftpRoot = ConfigurationManager.AppSettings["FTPRoot"]; using (var session = new WinSCP.Session()) { session.Open(sessionOptions); Log("Connected successfully to FTP server"); var transferOptions = new WinSCP.TransferOptions() { TransferMode = WinSCP.TransferMode.Binary }; //Ceheck and create folder String mftpFilePath = string.Format("/{0}/{1}年/{2}月/{3}/{4}.pdf", ftpRoot, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.ToString("yyyyMMddHHmmss")); //session.CreateDirectory(Constants.FTPRoot); FileInfo fi = new FileInfo(filename); var hResult = session.PutFiles(fi.FullName, mftpFilePath, false, transferOptions); hResult.Check(); } return(true); } catch { return(false); } }