解压到指定位置

解压到指定位置

我正在使用 putty 解压,它工作正常。但是,通过 .NET C# SSH 库使用相同的命令(人次SSH网) 给出不同的结果。

SshClient s = new SshClient("ssh_host", "ssh_port", "ssh_username", "ssh_password");
SshCommand c = s.RunCommand("unzip -o \"/home/parent/child/1.zip\ 1.txt"")

通过 putty 使用相同的命令,将其提取到“child”中,使用此命令,1.txt 最终会出现在“parent”中。 ssh命令的返回结果与Putty的返回结果相同:

Archive:  /home/parent/child/1.zip
extracting: 1.txt

为什么要提取一级?我能看到的唯一区别是我使用 cd 将自己定位到目录(在 Putty 中)。

答案1

或者使用 unzip 的 -d 选项指定要将文件解压到的目录。

SshCommand c = s.RunCommand("unzip -d /home/parent/child -o \"/home/parent/child/1.zip\ 1.txt"")

答案2

知道了。

SshCommand c = s.RunCommand("cd /home/parent/child/ && unzip -o 1.zip 1.txt"))

使用这种语法,我将自己定位到文件夹并进行解压缩。

相关内容