/// <summary> /// Lauch a WinSCP or FileZilla session /// </summary> /// <param name="s">The session to launch</param> /// <returns>The error message if the process fails to start</returns> public string launchOtherSession(Session s, LaunchSessionEventArgs.PROGRAM program) { String errMsg = ""; // Get all the values from the registry that we are interested in string hostname = s.Hostname; string username = s.Username; string protocol = s.Protocol; int portnumber = s.Portnumber; // Override the default username if stored in the hostname if (hostname != null && hostname.Contains("@")) { username = hostname.Substring(0, hostname.IndexOf("@")); if (hostname.IndexOf("@") < hostname.Length) { hostname = hostname.Substring(hostname.IndexOf("@") + 1); } } String execLocation = ""; String execArgs = ""; // Setup the FileZilla args if (program == LaunchSessionEventArgs.PROGRAM.FILEZILLA) { // Only bother if we have a hostname set if (hostname == null || hostname.Length == 0) { execArgs = ""; } else { // Setup the protocol and port Protocol fp = (Protocol)Properties.Settings.Default.FileZillaProtocol; switch (fp) { case Protocol.FTP: protocol = "ftp://"; portnumber = 21; break; case Protocol.FTPS: protocol = "ftps://"; portnumber = 990; break; case Protocol.SFTP: protocol = "sftp://"; portnumber = 22; break; case Protocol.AUTO: if (protocol.Equals("ssh", StringComparison.InvariantCultureIgnoreCase)) { protocol = "sftp://"; if (portnumber == -1) { portnumber = 22; } } else { protocol = "ftp://"; portnumber = 21; } break; } String password = ""; if (Properties.Settings.Default.FileZillaVersion == 2) { // Setup Pageaent auth if requested and the protocol is sftp if (protocol.Equals("sftp://") && Properties.Settings.Default.FileZillaAttemptKeyAuth == true) { password = "******"; } } else if (Properties.Settings.Default.FileZillaVersion == 3) { execArgs = "-l interactive "; } // Finalise the auth string String auth = ""; if (username != null && !(username.Equals(""))) { auth = username + password + "@"; } execArgs = execArgs + protocol + auth + hostname + ":" + portnumber; } execLocation = Properties.Settings.Default.FileZillaLocation; } else if (program == LaunchSessionEventArgs.PROGRAM.WINSCP) { // Setup the /ini option if (Properties.Settings.Default.WinSCPIniEnabled == true && Properties.Settings.Default.WinSCPIniLocation != null && !Properties.Settings.Default.WinSCPIniLocation.Equals("")) { execArgs = "/ini=\"" + Properties.Settings.Default.WinSCPIniLocation + "\" "; } // Setup the /privatekey option if (!(s.PrivateKeyLocation.Equals(""))) { execArgs = "/privatekey=\"" + s.PrivateKeyLocation + "\" "; } // Only bother if we have a hostname set if (hostname != null && hostname.Length != 0) { // Setup the protocol and port Protocol wp = (Protocol)Properties.Settings.Default.WinSCPProtocol; int wsVer = Properties.Settings.Default.WinSCPVersion; // FTP isn't supported for v3, so default to SFTP if (wsVer == 3 && wp == Protocol.FTP) { wp = Protocol.SFTP; } switch (wp) { case Protocol.FTP: protocol = "ftp://"; portnumber = 21; break; case Protocol.SFTP: protocol = "sftp://"; portnumber = 22; break; case Protocol.SCP: protocol = "scp://"; portnumber = 22; break; case Protocol.AUTO: if (protocol.Equals("ssh", StringComparison.InvariantCultureIgnoreCase)) { Protocol wpp = (Protocol)Properties.Settings.Default.WinSCPPrefProtocol; if (wpp == Protocol.SCP) { protocol = "scp://"; } else { protocol = "sftp://"; } if (portnumber == -1) { portnumber = 22; } } else if (wsVer == 4) { protocol = "ftp://"; portnumber = 21; } else { protocol = "sftp://"; portnumber = 22; } break; } // Finalise the auth string String auth = ""; if (username != null && !(username.Equals(""))) { auth = username + "@"; } execArgs = execArgs + protocol + auth + hostname + ":" + portnumber; } execLocation = Properties.Settings.Default.WinSCPLocation; } Process p = new Process(); p.StartInfo.FileName = execLocation; p.StartInfo.Arguments = execArgs; // Attempt to start the process try { p.Start(); } catch (Exception ex) { errMsg = ex.Message; } p.Close(); return(errMsg); }
/// <summary> /// Lauch a WinSCP or FileZilla session /// </summary> /// <param name="s">The session to launch</param> /// <returns>The error message if the process fails to start</returns> public string launchOtherSession(Session s, LaunchSessionEventArgs.PROGRAM program) { String errMsg = ""; // Get all the values from the registry that we are interested in string hostname = s.Hostname; string username = s.Username; string protocol = s.Protocol; int portnumber = s.Portnumber; bool authgssapi = s.Authgssapi; bool gssapifwd = s.Gssapifwd; // Override the default username if stored in the hostname if (hostname != null && hostname.Contains("@")) { username = hostname.Substring(0, hostname.IndexOf("@")); if (hostname.IndexOf("@") < hostname.Length) { hostname = hostname.Substring(hostname.IndexOf("@") + 1); } } String execLocation = ""; String execArgs = ""; // Setup the FileZilla args if (program == LaunchSessionEventArgs.PROGRAM.FILEZILLA) { // Only bother if we have a hostname set if (hostname == null || hostname.Length == 0) { execArgs = ""; } else { // Setup the protocol and port Protocol fp = (Protocol)Properties.Settings.Default.FileZillaProtocol; switch (fp) { case Protocol.FTP: protocol = "ftp://"; portnumber = 21; break; case Protocol.FTPS: protocol = "ftps://"; portnumber = 990; break; case Protocol.SFTP: protocol = "sftp://"; portnumber = 22; break; case Protocol.AUTO: if (protocol.Equals("ssh", StringComparison.InvariantCultureIgnoreCase)) { protocol = "sftp://"; if (portnumber == -1) { portnumber = 22; } } else { protocol = "ftp://"; portnumber = 21; } break; } String password = ""; if (Properties.Settings.Default.FileZillaVersion == 2) { // Setup Pageaent auth if requested and the protocol is sftp if (protocol.Equals("sftp://") && Properties.Settings.Default.FileZillaAttemptKeyAuth == true) { password = "******"; } } else if (Properties.Settings.Default.FileZillaVersion == 3) { execArgs = "-l interactive "; } // Finalise the auth string String auth = ""; if (username != null && !(username.Equals(""))) { auth = username + password + "@"; } execArgs = execArgs + protocol + auth + hostname + ":" + portnumber; } execLocation = Properties.Settings.Default.FileZillaLocation; } else if (program == LaunchSessionEventArgs.PROGRAM.WINSCP) { // Setup the /ini option if (Properties.Settings.Default.WinSCPIniEnabled == true && Properties.Settings.Default.WinSCPIniLocation != null && !Properties.Settings.Default.WinSCPIniLocation.Equals("")) { execArgs = execArgs + " /ini=\"" + Properties.Settings.Default.WinSCPIniLocation + "\""; } // Setup the /privatekey option if (!(s.PrivateKeyLocation.Equals(""))) { execArgs = execArgs + " /privatekey=\"" + s.PrivateKeyLocation + "\""; } // Only bother if we have a hostname set if (hostname != null && hostname.Length != 0) { // Setup the protocol and port Protocol wp = (Protocol)Properties.Settings.Default.WinSCPProtocol; int wsVer = Properties.Settings.Default.WinSCPVersion; // FTP isn't supported for v3, so default to SFTP if (wsVer == 3 && wp == Protocol.FTP) { wp = Protocol.SFTP; } switch (wp) { case Protocol.FTP: protocol = "ftp://"; portnumber = 21; break; case Protocol.SFTP: protocol = "sftp://"; portnumber = 22; break; case Protocol.SCP: protocol = "scp://"; portnumber = 22; break; case Protocol.AUTO: if (protocol.Equals("ssh", StringComparison.InvariantCultureIgnoreCase)) { Protocol wpp = (Protocol)Properties.Settings.Default.WinSCPPrefProtocol; if (wpp == Protocol.SCP) { protocol = "scp://"; } else { protocol = "sftp://"; } if (portnumber == -1) { portnumber = 22; } } else if (wsVer == 4) { protocol = "ftp://"; portnumber = 21; } else { protocol = "sftp://"; portnumber = 22; } break; } // We only do single signon for ssh protcols and only if we have a username // Support in WinSCP for GSS (kerberos) was first introduced in 3.6.1 if ((protocol.Equals("scp://") || protocol.Equals("sftp://")) && username != null && !(username.Equals(""))) { // If WinSCP Options is set to use PuTTY Session Information GSS settings then if authgssapi is true then we // are ready to move forward with single signon for WinSCP. bool wsGss = Properties.Settings.Default.WinSCPUseGss; if (wsGss == true && authgssapi) { if (gssapifwd) { execArgs = execArgs + " /rawsettings AuthGSSAPI=1 GSSAPIFwdTGT=1"; } else { execArgs = execArgs + " /rawsettings AuthGSSAPI=1"; } } } // Finalise the auth string String auth = ""; if (username != null && !(username.Equals(""))) { auth = username + "@"; } // Per WinSCP documentation /rawsettings must be placed after the URL if any. execArgs = protocol + auth + hostname + ":" + portnumber + execArgs; } execLocation = Properties.Settings.Default.WinSCPLocation; } Process p = new Process(); p.StartInfo.FileName = execLocation; p.StartInfo.Arguments = execArgs; // Attempt to start the process try { p.Start(); } catch (Exception ex) { errMsg = ex.Message; } p.Close(); return(errMsg); }