在Debian上使用SFTP傳輸大文件,可以遵循以下步驟:
首先,確保你的Debian系統上安裝了OpenSSH服務器。如果沒有安裝,可以使用以下命令進行安裝:
sudo apt update
sudo apt install openssh-server
啟動SSH服務并設置為開機自啟:
sudo systemctl start ssh
sudo systemctl enable ssh
默認情況下,SSH服務器已經配置了SFTP。如果你需要自定義SFTP配置,可以編輯/etc/ssh/sshd_config
文件:
sudo nano /etc/ssh/sshd_config
找到并修改以下行(如果它們存在):
Subsystem sftp /usr/lib/openssh/sftp-server
確保這一行沒有被注釋掉。
保存并退出編輯器后,重啟SSH服務以應用更改:
sudo systemctl restart ssh
現在你可以使用SFTP客戶端連接到你的Debian服務器并傳輸大文件。以下是使用命令行SFTP客戶端的示例:
sftp username@hostname
將username
替換為你的用戶名,hostname
替換為你的服務器地址。
在SFTP提示符下,使用put
命令上傳文件:
put /path/to/local/largefile.zip /path/to/remote/directory/largefile.zip
將/path/to/local/largefile.zip
替換為你本地文件的路徑,/path/to/remote/directory/largefile.zip
替換為你希望文件上傳到的遠程目錄和文件名。
同樣,在SFTP提示符下,使用get
命令下載文件:
get /path/to/remote/largefile.zip /path/to/local/directory/largefile.zip
將/path/to/remote/largefile.zip
替換為你希望下載的遠程文件路徑,/path/to/local/directory/largefile.zip
替換為你希望文件保存到的本地目錄和文件名。
對于非常大的文件,你可能希望監控傳輸進度??梢允褂?code>pv命令來顯示傳輸進度:
pv
如果尚未安裝pv
,可以使用以下命令安裝:
sudo apt install pv
pv
上傳文件pv /path/to/local/largefile.zip | sftp username@hostname:/path/to/remote/directory/largefile.zip
pv
下載文件sftp username@hostname:/path/to/remote/largefile.zip | pv > /path/to/local/directory/largefile.zip
通過這些步驟,你應該能夠在Debian上順利地使用SFTP傳輸大文件。