Call scripting/console interface from .NET API?

Advertisement

ziesemer
Joined:
Posts:
4
Location:
Appleton, WI

Call scripting/console interface from .NET API?

I am helping to support a series of somewhat complicated SFTP transfers. I've been nothing but impressed with the WinSCP .NET API – and have many successes already completed with various logins, checks, transfers, etc.

I'm not seeing anything current in the .NET API (https://winscp.net/eng/docs/library_session#methods) that would support sending a block of commands back to the scripting/console interface. Is this something that could be considered for inclusion?

I.e., this would allow for having some .NET framework classes, primarily responsible for creating the connection, authenticating, checking some assumptions, "work", and then closing the connection. (This has already solved some complexities that can't be done with the scripting/console interface.) However, this then needs to be called from another workflow program, which has already done some other processing (e.g. GPG-encrypting files, etc.) – and was already generating a script block, such as:
cd "dir1"
lcd "prod_dir1"
put "file1.txt"
put "file2.txt"
cd "dir2"
rm "file3.txt"
put "file3a.txt"
Is there a way that this could simply be called as the "work" from a .NET API? Such an API method would need to be named as to not be confused with the current ExecuteCommand - but could maybe be called ConsoleCommand or such? Even if it just accepted a single string to accept one line / command at a time – custom .NET code (outside of the WinSCP library) could then be written to read from a file, stream from STDIN, etc...

I found where the scripting / console interface is implemented at https://github.com/winscp/winscp/blob/master/source/core/Script.cpp. I'm not sure what it would take to add a bridge to be able to call this from .NET API. Alternatively, I could look at writing a .NET class that would effectively read the same scripting / console commands – and translate them into its own calls to the other .NET API methods...

Thanks!!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: Call scripting/console interface from .Net API?

Sorry, I do not understand, what this would be good for.
Why do you want to send put or rm command, instead of calling Session.PutFiles or Session.RemoveFiles method?

Reply with quote

ziesemer
Joined:
Posts:
4
Location:
Appleton, WI

Re: Call scripting/console interface from .Net API?

This is not urgent, but could be a nice-to-have – and just asking if it would be worth considering at all.

Yes, ultimately converting the existing scripting/console interface calls to the equivalent .NET API methods is what we already did. I even have things factored into separate "include" files in PowerShell per system integration to help support this. It's just that now, one of these files needs to be maintained per-integration – vs. just pulling in the text block of scripting/interface commands as illustrated and as they already had. Even these could be converted to PowerShell – and then have PowerShell evaluate the text as PowerShell code – but I'd much rather be able to have this restricted to something that can only run SFTP commands, and not a free-for-all for "now dynamically run any PowerShell you want here".

A similar consideration could be that in .NET, we can call out to the command-line, P/Invoke, or WMI, etc. – the flexibility remains to use the other legacy interfaces when still needed. Just seeing that WinSCP provides for 2 methods, but without the ability to call from one to another. (And for myself, I can't see a value in calling out of the scripting/console interface to .NET, but can see and do have a use-case for calling from .NET to the scripting/console interface.)

Thanks!

Reply with quote

Advertisement

You can post new topics in this forum