EvotecIT / Transferetto

Small PowerShell module with FTPS/SFTP functionality
MIT License
55 stars 14 forks source link

Run SFTP commands #8

Closed labarp1111 closed 3 years ago

labarp1111 commented 3 years ago

Hi, is it possible to run SFTP commands such as "cd", "ls", "pwd", etc. (with custom parameters/arguments) through this module? We have a SFTP server where we want to run some of these commands.

PrzemyslawKlys commented 3 years ago

Yes, it's in the examples

https://github.com/EvotecIT/Transferetto/blob/1feb05836211f04972a2e84f5ad079f0cfbe2705/Examples/Example08-ConnectSSH.ps1#L1-L19

Unless you want something more specific?

labarp1111 commented 3 years ago

I actually tried this example but it is not working in our environment because the SFTP user IDs do not have a shell associated with them. I think to connect over SSH we will require a Shell to be associated with the user. As such, was trying to find out if we can connect over SFTP and run these commands.

PrzemyslawKlys commented 3 years ago

I wonder if you're having any specific issues with cd/ls/pwd etc?

Maybe it's related to RemotePathTransformation? https://github.com/sshnet/SSH.NET/wiki/ScpClient:-Remote-path-transformation and I just need to add that option?

Although it is for SCP, not SFTP which I've not added yet.

using (var client = new ScpClient("HOST", 22, "USER", "PWD"))
{
    client.RemotePathTransformation = RemotePathTransformation.ShellQuote;
    client.Connect();
    ...
}

But generally there is $sftpClient.ChangeDirectory('test1') to cd into specific dir. There is $SftpClient.CreateDirectory, DeleteDirectory and so on, just I've not added it.

labarp1111 commented 3 years ago

We are trying to transfer files to an SFTP server running on Mainframe. After we connect to the SFTP server, the first command that we need to run is "ls /+mode=text" which sets the type conversion on the Mainframe side (from ASCII to EBCDIC). So generally this is what we do when we connect from the Unix side- sftp userid@mainframe_IP ls /+mode=text cd DIR get * exit

We want to try something similar from PowerShell.

PrzemyslawKlys commented 3 years ago

I don't see anything in the library that would help with that. Probably we would need to open a feature request in SSH.NET github and ask them if they have idea how to do it, and then we can try to translate it to powershell.

labarp1111 commented 3 years ago

oh..ok. Thank you for checking on this.