I am trying to copy files from one folder to another within the remote unix server. I am using a web application in C# and using Renci SSH.Net for the process. When I using the Cp command , in the readline additional space is getting added and I am getting error as
cp: cannot stat `folder1/folder_two/fol_three/changecolumn.txt': No such file or directory
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