{"id":13480,"date":"2022-01-05T02:05:23","date_gmt":"2022-01-05T02:05:23","guid":{"rendered":"https:\/\/linuxways.net\/?p=13480"},"modified":"2022-01-05T02:05:23","modified_gmt":"2022-01-05T02:05:23","slug":"how-to-transfer-files-between-local-and-remote-machines-using-sftp-protocol","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-transfer-files-between-local-and-remote-machines-using-sftp-protocol\/","title":{"rendered":"How to Transfer Files Between Local and Remote Machines Using SFTP Protocol"},"content":{"rendered":"<h2>What is SFTP?<\/h2>\n<p><a href=\"https:\/\/www.sftp.net\/\">Simple File Transfer Protocol (SFTP)<\/a> is a protocol that is used to transfer files between two devices over the internet. It runs over File Transfer Protocol (FTP) and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Secure_Shell\">Secure Shell (SSH)<\/a> protocols.<\/p>\n<p>While the protocol transfers files, it also protects against password sniffing, man-in-the-middle attack, and sensitive data exposure. It also preserves the integrity of the data with the help of encryption and cryptographic hash functions. It also authenticates both the client and server before giving access. This allows secure transfer of files.<\/p>\n<h2>Installation Guide<\/h2>\n<p>In this tutorial, I will show you how you can easily exchange files between local and remote machines using this super-handy file transfer protocol.<\/p>\n<p>For this guide, I have used <a href=\"https:\/\/linuxmint.com\/edition.php?id=288\">Linux Mint Cinamon 20.02<\/a> as my local machine and <a href=\"https:\/\/ubuntu.com\/download\/desktop\">Ubuntu 20.04 LTS<\/a> as my remote machine.<\/p>\n<p>The tutorial is divided into two parts. In the first part, you will see how to transfer a file from a remote machine to a local machine. In the other part, you will see how to transfer a file from your local machine to a remote machine.<\/p>\n<p>Let\u2019s get started!<\/p>\n<h3>Transfer file from a remote machine to a local machine<\/h3>\n<h4>Step 1: SSH to Remote Machine<\/h4>\n<p>The first step is to make an SSH connection to your remote machine. To do that, first, become a superuser using the following command:<\/p>\n<pre>sudo -i<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"219\" height=\"19\" class=\"wp-image-13481\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image.png\" \/><\/p>\n<p>Now that you have become a superuser, ssh to the remote machine you want to communicate with to get the file.<\/p>\n<pre>ssh nginx@192.168.10.23<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"304\" height=\"22\" class=\"wp-image-13482\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-1.png 304w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-1-300x22.png 300w\" sizes=\"auto, (max-width: 304px) 100vw, 304px\" \/><\/p>\n<h4>Step 2: Locate the file to transfer<\/h4>\n<p>Then, locate the file you want to copy. In this tutorial, I will create a new file to transfer it to my local machine.<\/p>\n<p>To do that, I will go to the \/etc directory by running the command below:<\/p>\n<pre>cd \/etc<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"64\" height=\"18\" class=\"wp-image-13483\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-2.png\" \/><\/p>\n<p>With the help of the touch command, I will create a new file with the name transfer.txt.<\/p>\n<pre>touch transfer.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"153\" height=\"18\" class=\"wp-image-13484\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-3.png 153w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-3-150x18.png 150w\" sizes=\"auto, (max-width: 153px) 100vw, 153px\" \/><\/p>\n<h4>Step 3: Establish an SFTP connection with the remote machine<\/h4>\n<p>Now, we will connect to the remote machine using sftp, as shown below:<\/p>\n<pre>sftp nginx@192.168.10.23<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"305\" height=\"22\" class=\"wp-image-13485\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-4.png 305w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-4-300x22.png 300w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/p>\n<p>If you see sftp written like this, that means you are in sftp mode. Now the local and remote machines can exchange files using this protocol.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"389\" height=\"52\" class=\"wp-image-13486\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-5.png 389w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-5-300x40.png 300w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/p>\n<h4>Step 4: Check which directories sftp interacts with<\/h4>\n<p>Before going ahead to transfer files, let\u2019s navigate a little to understand which directories sftp interacts with. Run the command below to know your present working directory:<\/p>\n<pre>pwd<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"249\" height=\"33\" class=\"wp-image-13487\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-6.png\" \/><\/p>\n<p>To see the local machine\u2019s present working directory, we\u2019ll use:<\/p>\n<pre>lpwd<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"243\" height=\"32\" class=\"wp-image-13488\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-7.png\" \/><\/p>\n<p>We can also change the directory we want to interact with. It is included in the second part of this guide.<\/p>\n<h4>Step 5: Transfer the file<\/h4>\n<p>Let\u2019s go to the \/etc directory where we created the transfer.txt file.<\/p>\n<pre>cd \/etc<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"112\" height=\"18\" class=\"wp-image-13489\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-8.png\" \/><\/p>\n<p>To send a file from the remote machine to the local machine, we use the get command followed by the filename as shown below:<\/p>\n<pre>get transfer.txt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"198\" height=\"18\" class=\"wp-image-13490\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-9.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"353\" height=\"15\" class=\"wp-image-13491\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-10.png 353w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-10-300x13.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/p>\n<p>Now got to your local system\u2019s root directory with the following command:<\/p>\n<pre>cd ~<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"42\" height=\"17\" class=\"wp-image-13492\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-11.png\" \/><\/p>\n<p>Use ls to see all the files in the directory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"79\" height=\"16\" class=\"wp-image-13493\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-12.png\" \/><\/p>\n<p>As you can see, the transfer.txt file is now in our local machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"119\" height=\"36\" class=\"wp-image-13494\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-13.png\" \/><\/p>\n<p>After closing the sftp session, you can transfer the file from your root directory to any other folder on your machine.<\/p>\n<h3>Transfer file from a local machine to a remote machine<\/h3>\n<p>Now that we have seen how to transfer a file from a remote machine to a local one, let\u2019s see how we can go in the opposite direction.<\/p>\n<p>We have another file test.txt on our local machine in the following directory path:<\/p>\n<pre>\/home\/azifa\/Downloads\/folder<\/pre>\n<p>From here we will transfer it to our remote machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"574\" class=\"wp-image-13495\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-14.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-14.png 800w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-14-300x215.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-14-768x551.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<h4>Step 1: Connect to the remote machine using SFTP<\/h4>\n<pre>sftp nginx@192.168.10.23<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"305\" height=\"22\" class=\"wp-image-13496\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-15.png 305w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-15-300x22.png 300w\" sizes=\"auto, (max-width: 305px) 100vw, 305px\" \/><\/p>\n<h4>Step 2: Change the local directory sftp interacts with<\/h4>\n<p>The local present working directory is:<\/p>\n<pre>lpwd<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"243\" height=\"32\" class=\"wp-image-13497\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-16.png\" \/><\/p>\n<p>As I told you earlier, we can change the local directory we want sftp to interact with. To do that, use the lcd command:<\/p>\n<pre> lcd \/home\/azifa\/Downloads\/folder<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"314\" height=\"18\" class=\"wp-image-13498\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-17.png 314w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-17-300x17.png 300w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/><\/p>\n<p>Before this, sftp was interacting with the local machine\u2019s root directory. Now it will interact with the \/home\/azifa\/Downloads\/folder directory. You can confirm it with the following command:<\/p>\n<pre>lpwd<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"39\" class=\"wp-image-13499\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-18.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-18.png 385w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-18-300x30.png 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/p>\n<h4>Step 4: Transfer the file<\/h4>\n<p>Next, we use the put command to transfer the file from the local machine to the remote machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"112\" height=\"21\" class=\"wp-image-13500\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-19.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"216\" height=\"16\" class=\"wp-image-13501\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-20.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"17\" class=\"wp-image-13502\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-21.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-21.png 611w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-21-300x8.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/p>\n<p>Run the ls command to see if the file has been successfully transferred to the \/home directory of the remote machine.<\/p>\n<pre>ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"79\" height=\"16\" class=\"wp-image-13503\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-22.png\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"85\" height=\"26\" class=\"wp-image-13504\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-23.png\" \/><\/p>\n<p>Yes, the file we transferred is here in the remote machine.<\/p>\n<p>Now you can end the session with a simple bye command.<\/p>\n<pre>bye<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"77\" height=\"17\" class=\"wp-image-13505\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/01\/word-image-24.png\" \/><\/p>\n<p>In this article, I explained to you how easily you can transfer files between a remote machine and a local machine with the help of a file transfer protocol known as SFTP. Using this method, you can exchange large files safely as it is a secure protocol that encrypts your data for protection.<\/p>\n<p>To see how you can set up a ProFTPD Server on Linux Mint 20, visit:<\/p>\n<p><a href=\"https:\/\/linuxways.net\/de\/centos\/install-proftpd-on-linux-mint-20\/\">https:\/\/linuxways.net\/mint\/install-proftpd-on-linux-mint-20\/<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>What is SFTP? Simple File Transfer Protocol (SFTP) is a protocol that is used to transfer files between two devices over the internet. It runs over File Transfer&hellip;<\/p>","protected":false},"author":1,"featured_media":13645,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[135,813],"class_list":["post-13480","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mint","category-ubuntu","tag-files-2","tag-sftp-protocol"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/13480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=13480"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/13480\/revisions"}],"predecessor-version":[{"id":13506,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/13480\/revisions\/13506"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/13645"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=13480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=13480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=13480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}