第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 SSH.NET SshClient 將文件從 Windows 復(fù)制到遠(yuǎn)程 Linux 服務(wù)器

使用 SSH.NET SshClient 將文件從 Windows 復(fù)制到遠(yuǎn)程 Linux 服務(wù)器

C#
GCT1015 2022-07-23 16:48:27
我正在使用 Visual Studio 和 C# Web 應(yīng)用程序。我正在嘗試使用 SSH.NET 將文件從 Windows 服務(wù)器移動(dòng)到遠(yuǎn)程 Linux 服務(wù)器SshClient。我正在嘗試下面的代碼,但文件沒(méi)有被復(fù)制。var filespath = FUupload.PostedFile.FileName.Replace("\\", "/");SshClient sshclient = new SshClient("hostname", "username", "pwd");sshclient.Connect();ShellStream stream = sshclient.CreateShellStream("cmsd", 80, 24, 800, 600, 1024);Label1.Text = sendCommand("sudo su - wwabc1", stream).ToString();Label2.Text = sendCommand("whoami", stream).ToString();Label3.Text = sendCommand("cp /" + filespath + " /wwabc1/test/folder_one/test/", stream).ToString();public StringBuilder sendCommand(string customCMD){    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;}我沒(méi)有收到任何錯(cuò)誤,但文件沒(méi)有移動(dòng)。
查看完整描述

1 回答

?
明月笑刀無(wú)情

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊

您不能使用 shell 命令在本地和遠(yuǎn)程機(jī)器之間傳輸文件。


想象一下,您正在使用 SSH 終端客戶端(PuTTY 行)。你可以cp在 PuTTY 中使用命令上傳文件嗎?- 你不能。


您必須使用 SFTP 協(xié)議。


SftpClient sftpclient = new SftpClient("hostname", "username", "pwd");

sftpclient.connect();

string localFilename = FUupload.PostedFile.FileName;

string remoteFilename = "/wwabc1/test/folder_one/test/" + Path.GetFileName(filename);

using (var fileStream = File.OpenRead(localFilename))

{

    sftpClient.UploadFile(fileStream, remoteFilename);

}


查看完整回答
反對(duì) 回復(fù) 2022-07-23
  • 1 回答
  • 0 關(guān)注
  • 196 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)