SharpSsh .NET ライブラリを使用して、.NET 経由で Linux で非常に単純なコマンドを実行しようとしています。コードは例外をスローせず、まだ機能していません。sudo php /www/data/{directory}/scripts/create_file.php
ターミナルからコマンドを実行すると、ファイルが作成されます。そしてsudo php /www/data/{directory}/scripts/delete_file.php
、ターミナルからコマンドを実行すると、ファイルが削除されます。このコードを .NET から呼び出すと、ファイルが作成/削除されていません。
セットアップについては、この回答を参照してください:
SharpSSH .NET ライブラリ: .NET から Linux (Debian) に接続できません
create_file.php:
<?php
$handle = fopen( 'test.txt', 'w' );
fwrite( $handle, 'Test Contents' );
fclose( $handle );
delete_file.php:
<?php
if( file_exists( 'test.txt' ) )
unlink( 'test.txt' );
.NET コード:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tamir.SharpSsh;
namespace Testing
{
public class Unix
{
public static void CreateFile()
{
SshExec ssh = new SshExec(Constants.LINUX_HOST, Constants.LINUX_USER, Constants.LINUX_PASSWORD);
ssh.Connect();
String result = ssh.RunCommand("sudo php " + Constants.PHP_SCRIPTS_DIR + "create_file.php");
}
public static void DeleteFile()
{
SshExec ssh = new SshExec(Constants.LINUX_HOST, Constants.LINUX_USER, Constants.LINUX_PASSWORD);
ssh.Connect();
String result = ssh.RunCommand("sudo php " + Constants.PHP_SCRIPTS_DIR + "delete_file.php");
}
}
}