Search code examples
c#tarscpwinscpwinscp-net

Extracting tarball C# using WinSCP .NET Assembly


I'm using WinSCP .NET Assembly in C# to transfer a tarball and extracting it.

My code works and I managed to copy the files. But my problem starts, when I try to extract them using session.ExecuteCommand. Nothing happens.

Trying to debug it I've added:

session.ExecuteCommand("touch /<path>/myfile.txt");

right after:

session.ExecuteCommand("tar -xzf /<path>/mytarball.tar.gz");

and the file is created, so the command and permission is not the problem and using:

result.Check();
string output = result.Output;

Shows that the files are extracted.

I'm using SCP protocol and not SFTP

Any suggesting ?

Br, Idan


Solution

  • It looks like you assume that the command will extract the files to /<path>.

    It won't. It extracts them to the current working directory (what is probably /home/user).

    Use -C (or --directory=) switch to specify the output directory:

    session.ExecuteCommand("tar -xzf /<path>/mytarball.tar.gz -C /<path>");