简体   繁体   中英

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

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>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM