SSH File Transfer

It's possible to transfer files with SSH.

[1] It's the exmaple for using SCP (Secure Copy).

# command = scp [Option] Source Target

# copy the [test.txt] on local to remote server [[email protected]]
[future@localhost ~]# scp ./test.txt [email protected]:/root
[email protected]'s password:     # remote server root password
test.txt                                                         100% 10 0.0KB/s 00:00

# copy the [test.txt] on remote to local server [future@localhost]
[future@localhost ~]# scp [email protected]:/root/test.txt ./test.txt
[email protected]'s password:     # remote server root password
test.txt                                                         100% 10 0.0KB/s 00:00
[future@localhost ~]#

[2] It's example to use SFTP (SSH File Transfer Protocol). SFTP server function 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].

# command = sftp [Option] [user@host]
[future@localhost ~]# sftp [email protected]
Connected to 192.168.1.250.
sftp>

# show current directory on remote server
sftp> pwd
Remote working directory: /root

# show current directory on local server
sftp> !pwd
/home/future

# show files in current directory on FTP server
sftp> ls -l
-rw-rw-r--    1 future    future        10 Sep 29 22:53 test.txt

# show files in current directory on local server
sftp> !ls -l
total 60
...
-rw-r--r--.  1 future    future          0 Sep 29 15:37 test.txt
...

# create a directory on remote server
sftp> mkdir testdir
sftp> ls -l
-rw-r--r--    1 root     root            0 Sep 29 15:37 test.txt
drwxr-xr-x    2 root     root         4096 Sep 29 16:02 testdir

# change directory
sftp> cd testdir
sftp> pwd
Remote working directory: /root/testdir

# go back to before directory
sftp> cd ..
sftp> pwd
Remote working directory: /root

# upload a file to remote server
sftp> put test.txt new.txt
Uploading test.txt to /root/new.txt
test.txt
sftp> ls -l
-rw-r--r--    1 root     root            0 Sep 29 16:08 new.txt
-rw-r--r--    1 root     root            0 Sep 29 15:37 test.txt
drwxr-xr-x    2 root     root         4096 Sep 29 16:02 testdir

# download a file from remote server
sftp> get test.txt
Fetching /root/test.txt to test.txt

# delete a directory on remote server
sftp> rmdir testdir
sftp> ls -l
-rw-r--r--    1 root     root            0 Sep 29 16:08 new.txt
-rw-r--r--    1 root     root            0 Sep 29 15:37 test.txt

# delete a file on remote server
sftp> rm test.txt
Removing /root/test.txt
sftp> ls -l
-rw-r--r--    1 root     root            0 Sep 29 16:08 new.txt

# execute commands with ![command]
sftp> !cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
...

# exit
sftp> quit