【原創】Linux基礎之linux服務器服務器間拷貝文件

linux服務器服務器間拷貝文件,有幾種方式:linux

1 若是是定時任務,能夠用rsync服務器

2 若是是基於ssh登陸,能夠用scp,優勢是能夠實現遠程到遠程的拷貝,缺點是須要帳號密碼ssh

upload: scp $local_file $remote_username@$remote_ip:$remote_folderip

download: scp $remote_username@$remote_ip:$remote_file $local_folderrem

3 若是隻是臨時傳文件,並且已經登陸到兩臺服務器上,有一種更簡單的方式,能夠用nctest

接收服務器A:nc -l $receive_port > $file_name
發送服務器B:nc $receive_ip $receive_port < $file_name登錄

能夠將服務器上的$file_name文件拷貝到服務器A上;
例如:定時任務

1.1.1.1: nc -l 8888 > test.log
1.1.1.2: nc 1.1.1.1 8888 < test.logfile

將1.1.1.2上的test.log拷貝到1.1.1.1上rsync

想要拷貝目錄?也很簡單:

接收服務器A:nc -l $receive_port |tar -zxvf -發送服務器B:tar -zcvf - $dir_name |nc $receive_ip $receive_port

相關文章
相關標籤/搜索