Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute script with FTP cause TikCommandUnexpectedResponseException #96

Open
Deantwo opened this issue Feb 23, 2024 · 1 comment · Fixed by Deantwo/tik4net#1 · May be fixed by #99
Open

Execute script with FTP cause TikCommandUnexpectedResponseException #96

Deantwo opened this issue Feb 23, 2024 · 1 comment · Fixed by Deantwo/tik4net#1 · May be fixed by #99

Comments

@Deantwo
Copy link
Contributor

Deantwo commented Feb 23, 2024

I am attempting to execute a /system/script/run command. The script is executed correctly on the router, but this library is failing with a tik4net.TikCommandUnexpectedResponseException exception.

Exception thrown: 'tik4net.TikCommandUnexpectedResponseException' in tik4net.dll
/system/script/run
.id=TestScript
MESSAGE: Single response sentence expected.
  COMMAND: /system/script/run
    .id=TestScript    Format: Default
  RESPONSE:
    ApiReSentence:.section=0
    ApiReSentence:.section=1
    ApiDoneSentence:

tik4net.TikCommandUnexpectedResponseException: Single response sentence expected.
  COMMAND: /system/script/run
    .id=TestScript    Format: Default
  RESPONSE:
    ApiReSentence:.section=0
    ApiReSentence:.section=1
    ApiDoneSentence:

   at tik4net.Api.ApiCommand.EnsureSingleResponse(IEnumerable`1 response)
   at tik4net.Api.ApiCommand.ExecuteNonQuery()
   at ...

It looks like it just doesn't like the ApiReSentence:.section=* lines.

In this example I have a basic script that downloads https://Deantwo.GitHub.io/Tik4Net/TestFtp.txt using the /tool fetch command.

TestScript script:

:log info "TestScript start"
/tool fetch url=("https://Deantwo.GitHub.io/Tik4Net/TestFtp.txt") dst-path=test.txt
:delay 5
:if ([:len [/file find name=test.txt]] != 0) do={
    :put [/file get [/file find name=test.txt] contents]
    /file remove test.txt
    :log info "TestScript HTTP test"
}
:log info "TestScript end"

C# test code:

const string SCRIPT_NAME = "TestScript"
MikrotikConnection conn = new MikrotikConnection();
conn.Start(_host, _user);
ITikCommand cmd = conn.CreateCommand("/system/script/run"
                                    , conn.Connection.CreateParameter(".id", SCRIPT_NAME)
                                    );
System.Diagnostics.Debug.WriteLine($"Script \"{SCRIPT_NAME}\" executing");
cmd.ExecuteNonQuery();
System.Diagnostics.Debug.WriteLine($"Script \"{SCRIPT_NAME}\" executed");

Router log:

TestScript start
fetch: file "test.txt" downloaded
TestScript HTTP test done
TestScript start

If I manually run the script through the terminal, I do get the "downloading" status thing text, and I assume that is what the .section=* messages are. So the API likely just have to ignore those?

[admin@router] > /system script run TestScript
      status: finished
  downloaded: 0KiB
       total: 0KiB
    duration: 1s

Hello danikf.
@Deantwo Deantwo changed the title Execute script with FTP cause Execute script with FTP cause TikCommandUnexpectedResponseException Feb 23, 2024
@Deantwo
Copy link
Contributor Author

Deantwo commented Mar 6, 2024

>/system/script/run
>=.id=TestScript
<!re
<=.section=0
<
<!re
<=.section=1
<
<!done
<

Deantwo added a commit to Deantwo/tik4net that referenced this issue Mar 7, 2024
Changed EnsureSingleResponse to ignore responses with only ".section" words.
Fixes danikf#96
@Deantwo Deantwo linked a pull request Mar 7, 2024 that will close this issue
@Deantwo Deantwo reopened this Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant