I'm trying to run a very simple command in Linux via .NET using the SharpSsh .NET library. The code doesn't throw any exceptions, and it's still not working. When I run the sudo php /www/data/{directory}/scripts/create_file.php
command from the terminal it creates the file. And when I run the sudo php /www/data/{directory}/scripts/delete_file.php
command from the terminal, it deletes the file. When calling this code from .NET, I don't see the file being created/deleted.
See this answer for setup:
SharpSSH .NET Library: unable to connect to Linux (Debian) from .NET
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 code:
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");
}
}
}