透過ssh發送文件

透過ssh發送文件

我需要使用 ssh 將文件發送到伺服器。我從來沒有使用過 ssh 所以這讓我很沮喪。我運行的是 Windows,伺服器運行的是 Ubuntu。

我使用 ssh2 IP 連接到伺服器,然後使用我擁有的帳戶登入。現在,我想將文件發送到伺服器中的一個資料夾,因此,我移動到該資料夾並使用以下命令:

scp test.txt user_name@host_direction server_folder_destination

它總是回傳它無法對 test.txt 執行「stat」、該檔案不存在等等。

我假設 ssh2 無法看到我的計算機根目錄 (C:) 中的文件,因此我嘗試指定更多並添加:C:\test.txt,但出現相同的錯誤。我不知道發生了什麼事。

有什麼提示嗎?

答案1

scp test.txt user_name@host_direction server_folder_destination

這不是正確的語法。你需要做這樣的事情:

scp test.txt user_name@host_direction:server_folder_destination

請注意:-- 告訴 scp 您要將本機檔案「test.txt」複製到主機host_direction,與使用者連接user_name,並將其儲存在其中server_folder_destination(預設相對於遠端使用者的主目錄)。請參閱SCP(1)手冊頁了解更多詳細資訊。

答案2

ssh用於遠端運行命令。使用scp(或sftp) 將檔案傳輸到遠端主機或從遠端主機傳輸檔案。

# send text.txt from this machine to /destination/path on remotehost
scp test.txt user@remotehost:/destination/path

# get test.txt from /foo/bar on remote host and store it here as foo.txt
scp user@remotehost:/foo/bar/test.txt foo.txt

相關內容