Thursday, February 15, 2007

SSH โอนข้อมูลผ่าน command line

หุหุหุ วันนี้ไปเจอทริปดีดี เลยจดบันทึกไว้ก่อนดีกว่า ปกติการโอนข้อมูลด้วยลีนุกส์นั้น จะใช้ Ftp, Samba, ssh วันนี้จะกล่าวถึง การโอนข้อมูลด้วย SSH แบบง่าย ๆ เลย เริ่มจากคำสั่งนี้

1. rsync

rsync -vaz -e ssh /home/akom/akom-beryl-settings.Profile administrator@xxxx.com:/home/administrator/
administrator@xxxx.com's password:

Source : /home/akom/
Target : administrator@xxxx.com:/home/administrator/

command: rsync -vaz -e ssh

-a : archive mode, preserve owner/group and permissions
-v : verbose
-z : compress data during transfer
-e : the remote shell to use

output

building file list ... done
akom-beryl-settings.Profile

sent 1841 bytes received 36 bytes 197.58 bytes/sec
total size is 4785 speedup is 2.55

* Date 20/12/2014 copy show Progress 
sudo rsync -avzh --progress Virtual/Winxp.img /media/hades/Volume2/
[sudo] password for hades:
sending incremental file list
Winxp.img
         21.47G 100%    9.83MB/s    0:34:43 (xfr#1, to-chk=0/1)

sent 21.48G bytes  received 35 bytes  10.30M bytes/sec
total size is 21.47G  speedup is 1.00

* Date 20170707 copy Folder show progress 
1.แบบข้ามเครื่อง
rsync -ahrvz --delete --stats --progress -e ssh folder user@192.168.0.xx:/home/user2/data
2.แบบอ่านไฟล์โฟลเดอร์
rsync -ahrvz --stats --progress --delete --files-from=/Path/location/Listfile.txt /mnt/Souce/ /mnt/destination/

แสดงผลการก็อปปี้
Number of files: 35
Number of files transferred: 16
Total file size: 16.23M bytes
Total transferred file size: 7.92M bytes
Literal data: 7.92M bytes
Matched data: 920 bytes
File list size: 1.06K
File list generation time: 0.003 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 4.65M
Total bytes received: 462

sent 4.65M bytes  received 462 bytes  344.53K bytes/sec

* Date 20171006 copy file เครื่องติดไวรัส Ransomeware ชนิด ykcol สั่งก็อปปี้แบบไม่เอาไฟล์ไวรัสมาด้วย

rsync -ahrvz --exclude='*.ykcol' --exclude='ykcol-*.htm' --stats --progress source /media/distination/

Exclude a specific file
rsync -avz --exclude 'dir1/dir2/file3.txt' source/ bobby@192.168.122.105:destination/
Exclude a specific directory
rsync -avz --exclude 'dir3' source/ bobby@192.168.122.105:destination/

Ref: rsync exclude

2. scp
command:
scp -r /path/filename user@domain.com:/directory
-r คือ Recursive ซึ่งเป็นการ copy directory และ subdirectory ด้วย

example:
root@nakom:# scp NamGyuri1.jpg administrator@www.xxxx.com:/home/administrator/tempfile
administrator@www.xxxx.com's password:
NamGyuri1.jpg 100% 71KB 70.5KB/s 00:01

copy from remote site to my computer

#scp -P xxxx file\ name/ user@mycomputer:/path/Folder

example:
scp -P xx001 file.txt user@192.168.1.100:/home/user/Downloads

example2: ย้ายโฟลเดอร์ และปลายทางไม่ใช้พอร์ต 22 ใช้พอร์ตอื่นแทน
scp -r -P 0000 New\ Folders/  user.a@192.168.0.1:/media/share5/download.s


stackoverflow

Reference:
1. wains
2. ubuntuclub

No comments: