Differences

This shows you the differences between the selected revisions of the page.

library_session_executecommand 2016-02-04 library_session_executecommand 2022-06-16 (current)
Line 8: Line 8:
<code vbnet *> <code vbnet *>
-Public Function ExecuteCommand(ByVal command As String) As CommandExecutionResult+Public Function ExecuteCommand(command As String) As CommandExecutionResult
</code> </code>
Line 25: Line 25:
| TimeoutException | Timeout waiting for ''winscp.com'' to respond. | | TimeoutException | Timeout waiting for ''winscp.com'' to respond. |
-===== Remarks =====+===== [[remarks]] Remarks =====
With [[protocols|SFTP and SCP protocols]], executes arbitrary [[remote_command|remote shell command]]. With [[protocols|SFTP and SCP protocols]], executes arbitrary [[remote_command|remote shell command]].
With FTP protocol, executes a protocol command. With FTP protocol, executes a protocol command.
Line 31: Line 31:
With SFTP protocol, that does not allow execution of arbitrary remote command, separate [[shell session]] will be automatically opened. With SFTP protocol, that does not allow execution of arbitrary remote command, separate [[shell session]] will be automatically opened.
-Not supported with WebDAV protocol.+Not supported with WebDAV and S3 protocols.
The command must not require user input. The command must not require user input.
-===== Example =====+===== [[example]] Example ===== 
==== [[csharp]] C# Example ==== ==== [[csharp]] C# Example ====
<code csharp> <code csharp>
Line 54: Line 55:
                UserName = "user",                 UserName = "user",
                Password = "mypassword",                 Password = "mypassword",
-                SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+                SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            };             };
Line 62: Line 63:
                session.Open(sessionOptions);                 session.Open(sessionOptions);
-                // Execute mysqldump on the server to dump all MySQL databases and compress the results+                // Execute mysqldump on the server to dump all MySQL databases and 
 +                // compress the results
                const string dbUsername = "USERNAME";                 const string dbUsername = "USERNAME";
                const string dbPassword = "PASSWORD";                 const string dbPassword = "PASSWORD";
Line 68: Line 70:
                string dumpCommand =                 string dumpCommand =
-                    string.Format("mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}", +                    string.Format( 
- ·································dbUsername, dbPassword, tempFilePath);+························"mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}", 
 + ·······················dbUsername, dbPassword, tempFilePath);
                session.ExecuteCommand(dumpCommand).Check();                 session.ExecuteCommand(dumpCommand).Check();
                // Download the database dump                 // Download the database dump
-                session.GetFiles(tempFilePath, "D:\\dbbackup\\").Check();+                session.GetFiles(tempFilePath, @"D:\dbbackup\").Check();
            }             }
Line 103: Line 106:
                .UserName = "user"                 .UserName = "user"
                .Password = "mypassword"                 .Password = "mypassword"
-                .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+                .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            End With             End With
Line 110: Line 113:
                session.Open(sessionOptions)                 session.Open(sessionOptions)
-                ' Execute mysqldump on the server to dump all MySQL databases and compress the results+                ' Execute mysqldump on the server to dump all MySQL databases and 
 +                ' compress the results
                Const dbUsername As String = "USERNAME"                 Const dbUsername As String = "USERNAME"
                Const dbPassword As String = "PASSWORD"                 Const dbPassword As String = "PASSWORD"
                Const tempFilePath As String = "/tmp/all_databases.gz"                 Const tempFilePath As String = "/tmp/all_databases.gz"
-                Dim dumpCommand As String = _ +                Dim dumpCommand As String = 
-                    String.Format("mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}", _+                    String.Format( 
 +························"mysqldump --opt -u {0} --password={1} --all-databases | gzip > {2}",
                        dbUsername, dbPassword, tempFilePath)                         dbUsername, dbPassword, tempFilePath)
                session.ExecuteCommand(dumpCommand).Check()                 session.ExecuteCommand(dumpCommand).Check()
Line 150: Line 155:
        UserName = "user"         UserName = "user"
        Password = "mypassword"         Password = "mypassword"
-        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+        SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
    }     }
Line 166: Line 171:
        $dumpCommand =         $dumpCommand =
-            ("mysqldump --opt -u {0} --password={1} --all-databases | gzip &gt; {2}" -+            "mysqldump --opt -u $dbUsername --password=$dbPassword --all-databases | &quot; + 
- ···············$dbUsername, $dbPassword, $tempFilePath)+············"gzip &gt; $tempFilePath&quot;
        $session.ExecuteCommand($dumpCommand).Check()         $session.ExecuteCommand($dumpCommand).Check()
Line 181: Line 186:
    exit 0     exit 0
} }
-catch [Exception]+catch
{ {
-    Write-Host $_.Exception.Message+    Write-Host "Error: $($_.Exception.Message)"
    exit 1     exit 1
} }
</code> </code>

Last modified: by martin