You are on page 1of 3

Debian 9 Stretch : SSH Server : SSH File Transfer(Debian) : Server World https://www.server-world.info/en/note?

os=Debian_9&p=ssh&f=2

SSH File Trans fer (Debian Client) 2017/06/21

It's possible to transfer files with SSH.

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

# how to ⇒ scp [Option] Source Target

# copy the [tes t.txt] on local to rem ote s erver [www.s rv.world]
debian@dlp:~$ scp ./test.txt debian@www.srv.world:~/
debian@10.0.0.30's password: # pas sword of the user
test.txt 100% 10 0.0KB/s 00:00

# copy the [/home /debian /tes t.txt] on remote server [www.srv.world] to the local
debian@dlp:~$ scp debian@www.srv.world:/home/debian/test.txt ./test.txt
debian@10.0.0.30's password:
test.txt 100% 10 0.0KB/s 00:00

[2] It's example to use SFTP (SSH File Transfer P rotocol). SFTP server function is
enabled by default, but if not, enable it to add the line [Subsystem sftp /usr /lib
/openssh /sftp-server] in [/etc /ssh /sshd̲config].

# s ftp [Option] [user@hos t]


debian@dlp:~$ sftp debian@www.srv.world
debian@www.srv.world's password: # password of the us er
Connected to www.srv.world.
sftp>

# s how current directory on remote s erver


sftp> pwd
Remote working directory: /home/debian

# s how current directory on local server


sftp> !pwd
/home/debian

# s how files in current directory on F TP s erver


sftp> ls -l
drwxrwxr-x 2 debian debian 6 Jul 29 21:33 public_html
-rw-rw-r-- 1 debian debian 10 Jul 28 22:53 test.txt

# s how files in current directory on local server


sftp> !ls -l
total 4
-rw-rw-r-- 1 debian debian 10 Jul 29 21:31 test.txt

Copy righ t © 2 0 0 7 -2 0 1 7 S er ver World A ll R igh ts Reser v ed.

1 dari 3 17/10/2017 9:54


Debian 9 Stretch : SSH Server : SSH File Transfer(Debian) : Server World https://www.server-world.info/en/note?os=Debian_9&p=ssh&f=2

# change directory
sftp> cd public_html
sftp> pwd
Remote working directory: /home/debian/public_html

# upload a file to remote server


sftp> put test.txt debian.txt
Uploading test.txt to /home/debian/debian.txt
test.txt 100% 10 0.0KB/s 00:00
sftp> ls -l
drwxrwxr-x 2 debian debian 6 Jul 29 21:33 public_html
-rw-rw-r-- 1 debian debian 10 Jul 29 21:39 debian.txt
-rw-rw-r-- 1 debian debian 10 Jul 28 22:53 test.txt

# upload some files to rem ote s erver


sftp> put *.txt
Uploading test.txt to /home/debian/test.txt
test.txt 100% 10 0.0KB/s 00:00
Uploading test2.txt to /home/debian/test2.txt
test2.txt 100% 0 0.0KB/s 00:00
sftp> ls -l
drwxrwxr-x 2 debian debian 6 Jul 29 21:33 public_html
-rw-rw-r-- 1 debian debian 10 Jul 29 21:39 debian.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:45 test.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:46 test2.txt

# download a file from remote server


sftp> get test.txt
Fetching /home/debian/test.txt to test.txt
/home/debian/test.txt 100% 10 0.0KB/s 00:00

# download s om e files from remote server


sftp> get *.txt
Fetching /home/debian/debian.txt to debian.txt
/home/debian/debian.txt 100% 10 0.0KB/s 00:00
Fetching /home/debian/test.txt to test.txt
/home/debian/test.txt 100% 10 0.0KB/s 00:00
Fetching /home/debian/test2.txt to test2.txt
/home/debian/test2.txt 100% 10 0.0KB/s 00:00

# create a directory on remote server


sftp> mkdir testdir
sftp> ls -l
drwxrwxr-x 2 debian debian 6 Jul 29 21:33 public_html
-rw-rw-r-- 1 debian debian 10 Jul 29 21:39 debian.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:45 test.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:46 test2.txt
drwxrwxr-x 2 debian debian 6 Jul 29 21:53 testdir
Copy righ t © 2 0 0 7 -2 0 1 7 S er ver World A ll R igh ts Reser v ed.

2 dari 3 17/10/2017 9:54


Debian 9 Stretch : SSH Server : SSH File Transfer(Debian) : Server World https://www.server-world.info/en/note?os=Debian_9&p=ssh&f=2

# delete a directory on remote server


sftp> rmdir testdir
rmdir ok, `testdir' remov ed
sftp> ls -l
drwxrwxr-x 2 debian debian 6 Jul 29 21:33 public_html
-rw-rw-r-- 1 debian debian 10 Jul 29 21:39 debian.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:45 test.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:46 test2.txt

# delete a file on remote server


sftp> rm test2.txt
Remov ing /home/debian/test2.txt
sftp> ls -l
drwxrwxr-x 2 debian debian 6 Jul 29 21:33 public_html
-rw-rw-r-- 1 debian debian 10 Jul 29 21:39 debian.txt
-rw-rw-r-- 1 debian debian 10 Jul 29 21:45 test.txt

# execute commands with "![com mand]"


sftp> !cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
...
...
debian:x:1001:1001::/home/debian:/bin/bash

# exit
sftp> quit
221 Goodbye.

Copy righ t © 2 0 0 7 -2 0 1 7 S er ver World A ll R igh ts Reser v ed.

3 dari 3 17/10/2017 9:54

You might also like