예제 #1
0
파일: Shell.cs 프로젝트: FherStk/AutoCheck
        /// <summary>
        /// Creates a new remote shell connector instance.
        /// </summary>
        /// <param name="remoteOS"The remote host OS.</param>
        /// <param name="host">Host address where the command will be run.</param>
        /// <param name="username">The remote machine's username which one will be used to login.</param>
        /// <param name="password">The remote machine's password which one will be used to login.</param>
        /// <param name="port">The remote machine's port where SSH is listening to.</param>
        public Shell(Utils.OS remoteOS, string host, string username, string password, int port = 22) : this()
        {
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException("host");
            }
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException("username");
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            this.RemoteOS    = remoteOS;
            this.Host        = host;
            this.Username    = username;
            this.Password    = password;
            this.Port        = port;
            this.RemoteShell = new Renci.SshNet.SshClient(this.Host, this.Port, this.Username, this.Password);
            this.FileSystem  = new Renci.SshNet.ScpClient(this.Host, this.Port, this.Username, this.Password);
        }
예제 #2
0
        /// <summary>
        /// Downloads a remote file into a temp folder, perfoms the action and removes the file.
        /// </summary>
        /// <param name="action">The action to run.</param>
        protected void ProcessRemoteFile(Utils.OS remoteOS, string host, string username, string password, int port, string filePath, Action <string> action)
        {
            var remote = new Shell(remoteOS, host, username, password, port);

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            if (!remote.ExistsFile(filePath))
            {
                throw new FileNotFoundException("filePath");
            }

            filePath = remote.DownloadFile(filePath);
            action.Invoke(filePath);

            Utils.RunWithRetry <IOException>(new Action(() => {
                //Note: GC must be invoked in order to avoid an System.IO.IOException (file in use by another process).
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
                File.Delete(filePath);
            }));
        }
예제 #3
0
파일: GDrive.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new remote connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="accountFilePath">Local path (not remote one) to the txt file containing the Google Drive account which will be used to login.</param>
 /// <param name="secretFilePath">Local path (not remote one) to the json file containing the Google Drive credentials which will be used to login.</param>
 public GDrive(Utils.OS remoteOS, string host, string username, string password, string accountFilePath, string secretFilePath) : this(remoteOS, host, username, password, 22, accountFilePath, secretFilePath)
 {
 }
예제 #4
0
파일: GDrive.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new remote connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="port">The remote machine's port where SSH is listening to.</param>
 /// <param name="accountFilePath">Local path (not remote one) to the txt file containing the Google Drive account which will be used to login.</param>
 /// <param name="secretFilePath">Local path (not remote one) to the json file containing the Google Drive credentials which will be used to login.</param>
 public GDrive(Utils.OS remoteOS, string host, string username, string password, int port, string accountFilePath, string secretFilePath) : this(accountFilePath, secretFilePath)
 {
     Remote = new Shell(remoteOS, host, username, password, port);
 }
예제 #5
0
파일: Html.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="filePath">HTML file path.</param>
 public Html(Utils.OS remoteOS, string host, string username, string password, string filePath) : this(remoteOS, host, username, password, 22, filePath)
 {
 }
예제 #6
0
파일: Html.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new remote connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="port">The remote machine's port where SSH is listening to.</param>
 /// <param name="filePath">HTML file path.</param>
 public Html(Utils.OS remoteOS, string host, string username, string password, int port, string filePath)
 {
     ProcessRemoteFile(remoteOS, host, username, password, port, filePath, new Action <string>((filePath) => {
         Parse(filePath);
     }));
 }
예제 #7
0
파일: Csv.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="filePath">CSV file path.</param>
 public Csv(Utils.OS remoteOS, string host, string username, string password, string filePath, char fieldDelimiter = ',', char textDelimiter = '"') : this(remoteOS, host, username, password, 22, filePath, fieldDelimiter, textDelimiter)
 {
 }
예제 #8
0
파일: Csv.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="port">The remote machine's port where SSH is listening to.</param>
 /// <param name="filePath">CSV file path.</param>
 public Csv(Utils.OS remoteOS, string host, string username, string password, int port, string filePath, char fieldDelimiter = ',', char textDelimiter = '"')
 {
     ProcessRemoteFile(remoteOS, host, username, password, port, filePath, new Action <string>((filePath) => {
         Parse(filePath, fieldDelimiter, textDelimiter);
     }));
 }
예제 #9
0
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="port">The remote machine's port where SSH is listening to.</param>
 /// <param name="filePath">XML file path.</param>
 /// <param name="validation">Validation type.</param>
 public Xml(Utils.OS remoteOS, string host, string username, string password, int port, string filePath, ValidationType validation = ValidationType.None)
 {
     ProcessRemoteFile(remoteOS, host, username, password, port, filePath, new Action <string>((filePath) => {
         Parse(filePath, validation);
     }));
 }
예제 #10
0
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="filePath">XML file path.</param>
 /// <param name="validation">Validation type.</param>
 public Xml(Utils.OS remoteOS, string host, string username, string password, string filePath, ValidationType validation = ValidationType.None) : this(remoteOS, host, username, password, 22, filePath, validation)
 {
     //This method can be avoided if the overload containing the 'port' argument moves it to the end and makes it optional, but then the signature becomes inconsistent compared with the remoteShell constructor...
 }
예제 #11
0
파일: Atom.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="port">The remote machine's port where SSH is listening to.</param>
 /// <param name="filePath">Atom file path.</param>
 public Atom(Utils.OS remoteOS, string host, string username, string password, int port, string filePath) : base(remoteOS, host, username, password, port, filePath)
 {
 }
예제 #12
0
파일: Rss.cs 프로젝트: FherStk/AutoCheck
 /// <summary>
 /// Creates a new connector instance.
 /// </summary>
 /// <param name="remoteOS"The remote host OS.</param>
 /// <param name="host">Host address where the command will be run.</param>
 /// <param name="username">The remote machine's username which one will be used to login.</param>
 /// <param name="password">The remote machine's password which one will be used to login.</param>
 /// <param name="port">The remote machine's port where SSH is listening to.</param>
 /// <param name="filePath">RSS file path.</param>
 public Rss(Utils.OS remoteOS, string host, string username, string password, int port, string filePath) : base(remoteOS, host, username, password, port, filePath, ValidationType.None)
 {
 }