OpenSSH : SSH File Transfer (CentOS)2024/12/19 |
It's possible to transfer files via SSH. |
|
[1] | It's the example for using SCP (Secure Copy). |
# command ⇒ scp [Option] Source Target
# copy the [test.txt] on localhost to remote host [node01.srv.world] [cent@dlp ~]$ scp ./testfile.txt cent@node01.srv.world:~/
cent@node01.srv.world's password: # password of the user
testfile.txt 100% 685KB 71.9MB/s 00:00
# copy the [/home/cent/test.txt] on remote host [node01.srv.world] to the localhost [cent@dlp ~]$ scp cent@node01.srv.world:/home/cent/testfile.txt ./testfile2.txt cent@node01.srv.world's password: testfile.txt 100% 685KB 185.6MB/s 00:00 |
[2] | It's the examples to use SFTP (SSH File Transfer Protocol). SFTP server feature is enabled by default, but if not, enable it to add the line [Subsystem sftp /usr/libexec/openssh/sftp-server] in [/etc/ssh/sshd_config]. |
# sftp [Option] [user@host] [cent@dlp ~]$ sftp cent@node01.srv.world cent@node01.srv.world's password: # password of the user Connected to node01.srv.world. sftp> # show current directory on remote host sftp> pwd Remote working directory: /home/cent # show current directory on localhost sftp> !pwd /home/cent # show files in current directory on remote host sftp> ls -l drwxr-xr-x ? cent cent 6 Dec 19 11:08 testdir -rw-r--r-- ? cent cent 701707 Dec 19 11:05 testfile.txt # show files in current directory on localhost sftp> !ls -l total 1376 -rw-r--r--. 1 cent cent 701707 Dec 19 11:06 testfile2.txt -rw-r--r--. 1 cent cent 701707 Dec 19 11:04 testfile.txt # change directory sftp> cd testdir sftp> pwd Remote working directory: /home/cent/testdir # upload a file to remote host sftp> put testfile.txt testfile3.txt Uploading testfile.txt to /home/cent/testdir/testfile3.txt testfile.txt 100% 685KB 188.7MB/s 00:00 sftp> ls -l -rw-r--r-- ? cent cent 701707 Dec 19 11:10 testfile3.txt # upload some files to remote host sftp> put *.txt Uploading testfile.txt to /home/cent/testdir/testfile.txt testfile.txt 100% 685KB 294.0MB/s 00:00 Uploading testfile2.txt to /home/cent/testdir/testfile2.txt testfile2.txt 100% 685KB 290.4MB/s 00:00 100% 0 0.0KB/s 00:00 sftp> ls -l -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile2.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:10 testfile3.txt # download a file from remote host sftp> get testfile.txt testfile4.txt Fetching /home/cent/testdir/testfile.txt to testfile4.txt testfile.txt 100% 685KB 219.8MB/s 00:00 # download some files from remote host sftp> get *.txt Fetching /home/cent/testdir/testfile.txt to testfile.txt testfile.txt 100% 685KB 313.8MB/s 00:00 Fetching /home/cent/testdir/testfile2.txt to testfile2.txt testfile2.txt 100% 685KB 388.1MB/s 00:00 Fetching /home/cent/testdir/testfile3.txt to testfile3.txt testfile3.txt 100% 685KB 348.2MB/s 00:00 # create a directory on remote host sftp> mkdir testdir2 sftp> ls -l drwxr-xr-x ? cent cent 6 Dec 19 11:14 testdir2 -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile2.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:10 testfile3.txt # delete a directory on remote host sftp> rmdir testdir2 sftp> ls -l -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile2.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:10 testfile3.txt # delete a file on remote host sftp> rm testfile3.txt Removing /home/cent/testdir/testfile3.txt sftp> ls -l -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile.txt -rw-r--r-- ? cent cent 701707 Dec 19 11:11 testfile2.txt # execute commands with ![command] sftp> !cat /etc/passwd root:x:0:0:Super User:/root:/bin/bash bin:x:1:1:bin:/bin:/usr/sbin/nologin daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin adm:x:3:4:adm:/var/adm:/usr/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync ..... ..... # exit sftp> quit |
Sponsored Link |
|