[英]Copying files within Remote unix server using Renci SSH.NET
I am trying to copy files from one folder to another within the remote unix server. 我正在尝试将文件从一个文件夹复制到远程UNIX服务器中的另一个文件夹。 I am using a web application in C# and using Renci SSH.Net for the process.
我在C#中使用Web应用程序,并在此过程中使用Renci SSH.Net。 When I using the Cp command , in the readline additional space is getting added and I am getting error as
当我使用Cp命令时,在阅读行中添加了额外的空间,并且由于
cp: cannot stat `folder1/folder_two/fol_three/changecolumn.txt': No such file or directory
cp:无法统计`folder1 / folder_two / fol_three / changecolumn.txt':没有这样的文件或目录
I have used the below code: 我使用了以下代码:
SshClient sshclient = new SshClient("hostname", "username", "pwd");
sshclient.Connect();
ShellStream stream = sshclient.CreateShellStream("cmsd", 80, 24, 800, 600, 1024);
sendCommand("sudo su - wwabc1", stream).ToString();
sendCommand("whoami", stream).ToString();
sendCommand("cp / folder1/folder_two/fol_three/" + uploadedfileName + uploadedfileExt + " /Target1/folder1/folder_two/target/", stream).ToString();
public StringBuilder sendCommand(string customCMD, ShellStream stream)
{
StringBuilder answer;
var reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
writer.AutoFlush = true;
WriteStream(customCMD, writer, stream);
answer = ReadStream(reader);
return answer;
}
private void WriteStream(string cmd, StreamWriter writer, ShellStream stream)
{
writer.WriteLine(cmd);
while (stream.Length == 0)
{
Thread.Sleep(500);
}
}
private StringBuilder ReadStream(StreamReader reader)
{
StringBuilder result = new StringBuilder();
string line;
while ((line = reader.ReadLine()) != null)
{
result.AppendLine(line);
}
return result;
}
The result is having the data as below: 结果是具有以下数据:
cp / folder1/folder_two/fol_three/changecolumn
< cp / folder1/folder_two/fol_three/changecolumnn ame.txt /wwabc1/Target1
</test_files/changecolumnname.txt /wwabc1/Target1/ folder1/folder_two/target/
cp: omitting directory `/'
cp: cannot stat `folder1/folder_two/fol_three//changecolumnname.txt': No such file or directory
[wwabc1@host ~]$
[wwabc1@host ~]$
There is too much blank space added in between, but I am passing the information without the spaces in between. 两者之间添加了太多空白,但是我传递的信息之间没有空格。 How to fix this?
如何解决这个问题? Thanks
谢谢
Here: 这里:
sendCommand("cp / folder1...
Notice the space after the first /
. 注意第一个
/
之后的空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.