{"id":16083,"date":"2019-03-20T14:58:03","date_gmt":"2019-03-20T14:58:03","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=16083"},"modified":"2026-03-10T09:37:09","modified_gmt":"2026-03-10T09:37:09","slug":"how-to-use-sftp-to-safely-transfer-files","status":"publish","type":"post","link":"\/ph\/tutorials\/how-to-use-sftp-to-safely-transfer-files\/","title":{"rendered":"How to use SFTP (ssh file transfer protocol)"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>FTP is the standard method of transferring files or other data between computers, but it&rsquo;s becoming more and more outdated in today&rsquo;s security-conscious environment. Fortunately, that&rsquo;s where SFTP comes in, which is particularly useful for VPS hosting users.<\/p><p>In this guide, we&rsquo;re going to show how to use SFTP for secure file transfer, talk about some other useful commands and elaborate more on how it works.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/SSH-Cheat-Sheet-EN.pdf\" target=\"_blank\" rel=\"noopener\">Download ultimate SSH commands cheat sheet<\/a><\/p><p>\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-connect-using-sftp\">How to Connect Using SFTP?<\/h2><p>SFTP is a subsystem of SSH. Hence, it supports all SSH authentication methods. While it&rsquo;s easier to set up and use password authentication, it&rsquo;s much more convenient and safer to create SSH keys for a passwordless SFTP login.<\/p><p>You can check <a href=\"\/ph\/tutorials\/ssh\/how-to-set-up-ssh-keys\" target=\"_blank\" rel=\"noopener noreferrer\">this tutorial<\/a> on how to set up your SSH keys. Once you&rsquo;re ready, follow the steps below to connect with SFTP:<\/p><ol class=\"wp-block-list\">\n<li>Check your SSH access using one of these commands:\n<pre>ssh user@server_ipaddress\nssh user@remotehost_domainname<\/pre>\n<\/li>\n\n\n\n<li>Once that is done, leave the session if no errors occurred.<\/li>\n\n\n\n<li>Initiate an SFTP connection with the following commands:\n<pre>sftp user@server_ipaddress\nsftp user@remotehost_domainname<\/pre>\n<\/li>\n\n\n\n<li>If you&rsquo;re using a custom SSH port, use one of these commands to change the SFTP port:\n<pre class=\"ql-syntax\">sftp -oPort=customport user@server_ipaddress\nsftp -oPort=customport user@remotehost_domainname<\/pre>\n<\/li>\n\n\n\n<li>Here&rsquo;s how it should look like:\n<pre>sftp -oPort=49166 user@31.220.57.32<\/pre>\n<\/li>\n<\/ol><p>Once you&rsquo;re connected, you will see an SFTP prompt.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-transfer-files-using-sftp\">How to Transfer Files Using SFTP?<\/h2><p>Here we&rsquo;re going to show you how to transfer remote files to the local system using SFTP and vice versa.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>You can also transfer your files using SFTP clients, such as FileZilla. Learn <a href=\"\/ph\/tutorials\/ftp\/filezilla-ftp-configuration\">how to use FileZilla<\/a> with our comprehensive guide.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-transferring-remote-files-from-a-server-to-the-local-system\">Transferring Remote Files From a Server to the Local System<\/h3><p>To start, let&rsquo;s check which local and which remote working directory we are using. To do this, we&rsquo;ll use these SFTP commands:<\/p><pre class=\"wp-block-preformatted\">sftp&gt; lpwd\nLocal directory: \/LocalDirectory\nsftp&gt; pwd\nRemote directory: \/RemoteDirectory\n<\/pre><p>Now, let&rsquo;s see how to transfer a file from a remote server to your local machine using the <strong>get<\/strong> command. Here&rsquo;s the basic syntax of the <strong>get<\/strong> command:<\/p><pre class=\"wp-block-preformatted\">get \/RemoteDirectory\/filename.txt\n<\/pre><p>For example, to copy the file <strong>\/etc\/xinetd.conf<\/strong> from the remote server to your local machine, you would use:<\/p><pre class=\"wp-block-preformatted\">get \/etc\/xinetd.conf\n<\/pre><p>Once the download is complete, you can now find that the file <strong>xinetd.conf <\/strong>is&nbsp;in the <strong>\/user\/home<\/strong> directory of your local machine.<\/p><p>To download multiple files with SFTP, use the <strong>mget<\/strong> command. To download all files in a directory called <strong>\/etc<\/strong> that have the <strong>.conf<\/strong> extension to your current working directory, you will use the following command:<\/p><pre class=\"wp-block-preformatted\">mget \/etc\/*.conf\n<\/pre><p>After the download, you can find all <strong>*.conf<\/strong> files in<strong> \/user\/home<\/strong> directory of your local machine.<\/p><h3 class=\"wp-block-heading\" id=\"h-transferring-files-from-the-local-machine-to-a-remote-server\">Transferring Files From the Local Machine to a Remote Server<\/h3><p>To copy a file from the local machine to the remote server, we&rsquo;ll use the <strong>get<\/strong> command again. In this case, the syntax of <strong>get<\/strong> command will be:<\/p><pre class=\"wp-block-preformatted\">get file.txt \/RemoteDirectory\n<\/pre><p>To move the file <strong>example.txt<\/strong> from a local machine to the remote machine, enter the following command:<\/p><pre class=\"wp-block-preformatted\">put \/home\/user-name\/example.txt \/root\n<\/pre><p>Now we will find the file in the remote server&rsquo;s root directory. You can also try transferring multiple files using the&nbsp;<strong>mput<\/strong> command. It works nearly the same as <strong>mget<\/strong>:<\/p><pre class=\"wp-block-preformatted\">mput \/home\/user-name\/*.txt \/root\n<\/pre><p>This command would move all files with the <strong>.txt<\/strong> extension in the <strong>\/home\/user-name<\/strong> from the local machine to the remote <strong>\/root<\/strong> directory.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>Keep in mind that to download and upload the files with SFTP, you will need to type the command <strong>put<\/strong> or <strong>get<\/strong> and press the <strong>TAB<\/strong> key.<\/p>\n                <\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-commands-for-navigating-with-sftp\">Commands for Navigating With SFTP<\/h2><p>Some commands can be used to navigate through the remote and local servers more efficiently with SFTP. They&rsquo;re similar to the ones you&rsquo;d use in the Linux shell prompt.<\/p><p>For example, the <strong>pwd<\/strong> command is always useful to let you know in which working directory you are currently on.<\/p><pre class=\"wp-block-preformatted\">sftp&gt; pwd\nRemote directory: \/RemoteDirectory\n<\/pre><p>or<\/p><pre class=\"wp-block-preformatted\">sftp&gt; lpwd\nLocal directory: \/LocalDirectory\n<\/pre><p>You can also display the list of files and directories you&rsquo;re using for the remote directory:<\/p><pre class=\"wp-block-preformatted\">ls\n<\/pre><p>Similarly, for the local working directory:<\/p><pre class=\"wp-block-preformatted\">lls\n<\/pre><p>For instance, the output will look similar to this:<\/p><pre class=\"wp-block-preformatted\">Pictures&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Templates&nbsp; &nbsp; &nbsp;Media&nbsp; &nbsp; &nbsp;Text.txt&nbsp; &nbsp; &nbsp;Documents\n<\/pre><p>To switch from one remote working directory to another local working directory, enter the following commands:<\/p><pre class=\"wp-block-preformatted\">cd name_of_directory\nlcd name_of_directory\n<\/pre><p>Finally, use the <strong>!<\/strong> and <strong>exit<\/strong> commands to go back to the local shell and quit SFTP.<\/p><h2 class=\"wp-block-heading\" id=\"h-basics-of-file-maintenance-using-sftp\">Basics of File Maintenance Using SFTP<\/h2><p>With SFTP, you can also manage directories and files using specific commands.<\/p><p>To check the remote server&rsquo;s disk space in gigabytes, use the <strong>df<\/strong> function like so:<\/p><pre class=\"wp-block-preformatted\">df -h\n<\/pre><p>Here&rsquo;s an output example:<\/p><pre class=\"wp-block-preformatted\">Filesystem &nbsp; &nbsp; &nbsp; &nbsp; Size&nbsp; Used Avail Use% Mounted on\n\/dev\/ploop29212p1 &nbsp; 59G&nbsp; 2.5G &nbsp; 56G &nbsp; 5% \/\nnone &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1.5G &nbsp; &nbsp; 0&nbsp; 1.5G &nbsp; 0% \/sys\/fs\/cgroup\nnone &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1.5G &nbsp; &nbsp; 0&nbsp; 1.5G &nbsp; 0% \/dev\ntmpfs&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1.5G &nbsp; &nbsp; 0&nbsp; 1.5G &nbsp; 0% \/dev\/shm\ntmpfs&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1.5G&nbsp; 568K&nbsp; 1.5G &nbsp; 1% \/run\ntmpfs&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 308M &nbsp; &nbsp; 0&nbsp; 308M &nbsp; 0% \/run\/user\/0\n<\/pre><p>Use the <strong>mkdir<\/strong> command to create a new directory on either the remote and local server :<\/p><pre class=\"wp-block-preformatted\">mkdir name_of_directory\nlmkdir name_of_directory\n<\/pre><p>You can delete one from the remote server using the <strong>rmdir<\/strong> command:<\/p><pre class=\"wp-block-preformatted\">rmdir name_of_directory\n<\/pre><p>Meanwhile, renaming a remote file is also rather straightforward:<\/p><pre class=\"wp-block-preformatted\">rename filename new_filename\n<\/pre><p>Here&rsquo;s an example:<\/p><pre class=\"wp-block-preformatted\">rename Old_FileExample New_FileExample\n<\/pre><p>If you want to remove a remote file, use the <strong>rm<\/strong> command:<\/p><pre class=\"wp-block-preformatted\">rm filename\n<\/pre><p>While the <a href=\"\/ph\/tutorials\/linux-chown-command\/\"><strong>chown<\/strong> command<\/a> is used to replace a file&rsquo;s owner:<\/p><pre class=\"wp-block-preformatted\">chown userid filename\n<\/pre><p><strong>userid<\/strong> can either be a <strong>username<\/strong> or a <strong>numeric user ID<\/strong>. For instance:<\/p><pre class=\"wp-block-preformatted\">chown UserOne FileExample\nchown 1234 FileExample\n<\/pre><p><strong>chgrp<\/strong> is used for changing a file&rsquo;s group owner:<\/p><pre class=\"wp-block-preformatted\">chgrp groupid filename\n<\/pre><p>For instance:<\/p><pre class=\"wp-block-preformatted\">chgrp NewGroup FileExample\n<\/pre><p>Finally, you will need to <a href=\"\/ph\/tutorials\/vps\/change-linux-permissions-and-owners\">change a file permission using the <strong>chmod<\/strong> interactive command<\/a>:<\/p><pre class=\"wp-block-preformatted\">chmod 764 FileExample\n<\/pre><p>In this example, the three-digit value stands for the file&rsquo;s <strong>user<\/strong>, <strong>group<\/strong>, and <strong>other<\/strong> users.<\/p><p>As for the permissions to <strong>read (r)<\/strong>, <strong>write (w)<\/strong>, and <strong>execute (x)<\/strong>, their values are <strong>4<\/strong>, <strong>2<\/strong>, <strong>1<\/strong>, respectively. <strong>0<\/strong> can also be used to provide no permissions.<\/p><p>To assign permissions, simply calculate the total values for each user class. Here&rsquo;s a breakdown of the example:<\/p><pre class=\"wp-block-preformatted\">chmod ugo FileExample\n# u represents the User who'll be able to read, write and execute the file.\n# g is for Groups, here we've given the permission to write and execute the file.\n# o or Others will only be able to read the file.\n<\/pre><h2 class=\"wp-block-heading\" id=\"h-list-of-useful-sftp-commands\">List of Useful SFTP Commands<\/h2><p>If you need a quick cheat sheet, here&rsquo;s a list of all the available SFTP commands. You can find this list yourself by simply entering the <strong>help<\/strong> or <strong>?<\/strong> command &mdash; both will prompt the same result.<\/p><pre class=\"wp-block-preformatted\">bye                                Quit sftp\ncd path                            Change remote directory to 'path'\nchgrp [-h] grp path                Change group of file 'path' to 'grp'\nchmod [-h] mode path               Change permissions of file 'path' to 'mode'\nchown [-h] own path                Change owner of file 'path' to 'own'\ndf [-hi] [path]                    Display statistics for current directory or\n                                   filesystem containing 'path'\nexit                               Quit sftp\nget [-afpR] remote [local]         Download file\nhelp                               Display this help text\nlcd path                           Change local directory to 'path'\nlls [ls-options [path]]            Display local directory listing\nlmkdir path                        Create local directory\nln [-s] oldpath newpath            Link remote file (-s for symlink)\nlpwd                               Print local working directory\nls [-1afhlnrSt] [path]             Display remote directory listing\nlumask umask                       Set local umask to 'umask'\nmkdir path                         Create remote directory\nprogress                           Toggle display of progress meter\nput [-afpR] local [remote]         Upload file\npwd                                Display remote working directory\nquit                               Quit sftp\nreget [-fpR] remote [local]        Resume download file\nrename oldpath newpath             Rename remote file\nreput [-fpR] local [remote]        Resume upload file\nrm path                            Delete remote file\nrmdir path                         Remove remote directory\nsymlink oldpath newpath            Symlink remote file\nversion                            Show SFTP version\n!command                           Execute 'command' in local shell\n!                                  Escape to local shell\n<\/pre><h2 class=\"wp-block-heading\" id=\"h-what-is-sftp\">What Is SFTP?<\/h2><p><strong>SFTP,<\/strong> or <strong>SSH File Transfer Protocol<\/strong> for short, is a much more secure way to move files. Using the <a href=\"https:\/\/www.ssh.com\/ssh\/protocol\" target=\"_blank\" rel=\"noopener noreferrer\">SSH protocol<\/a>, it supports encryption and other security methods used to better protect file transfers. It&rsquo;s the only secure file transfer protocol that protects against attacks at any point in the data transfer process, making it the preferred protocol.<\/p><p>During file transfer, all of the data is divided into packets and sent through a single secure connection.<\/p><p>Sensitive information will be encrypted and made unreadable when being transferred between the client and the server. In other words, the original content (plaintext) will be replaced by an incoherent string of characters (ciphertext).<\/p><p>Only the recipient with the required decryption key will be able to see the original content. This prevents any unauthorized access during file transfer.<\/p><p>Regular file transfer protocol (FTP) has two different channels to exchange data &mdash; the command channel and the data channel. In contrast, SFTP has only one encrypted channel where the data is exchanged in encrypted, formatted packets.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-full\"><a href=\"\/ph\/web-hosting\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/11\/Web-hosting_in-text-banner.png 1024w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/11\/Web-hosting_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/11\/Web-hosting_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/11\/Web-hosting_in-text-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>That pretty much covers the basics of how to use SFTP for secure file transfer. We hope this tutorial has proved to be useful. If you have any more questions, don&rsquo;t hesitate to leave a comment down below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FTP is the standard method of transferring files or other data between computers, but it&rsquo;s becoming more and more outdated in today&rsquo;s security-conscious environment. Fortunately, that&rsquo;s where SFTP comes in, which is particularly useful for VPS hosting users. In this guide, we&rsquo;re going to show how to use SFTP for secure file transfer, talk about [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ph\/tutorials\/how-to-use-sftp-to-safely-transfer-files\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Use SFTP to Safely Transfer Files: A Step-by-Step Guide","rank_math_description":"SFTP is the secure way of transfering files accross different machines. In this article, we'll teach you all about its essential commands.","rank_math_focus_keyword":"how to use sftp","footnotes":""},"categories":[22639],"tags":[],"class_list":["post-16083","post","type-post","status-publish","format-standard","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-use-sftp-to-safely-transfer-files","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/sftp","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-usar-sftp","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/transfer-file-dengan-sftp","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-use-sftp-to-safely-transfer-files","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-use-sftp-to-safely-transfer-files\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-use-sftp-to-safely-transfer-files\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/productos-para-vender-11","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-usar-sftp","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-usar-sftp","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-use-sftp-to-safely-transfer-files","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-use-sftp-to-safely-transfer-files","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-use-sftp-to-safely-transfer-files","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-use-sftp-to-safely-transfer-files","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/16083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/comments?post=16083"}],"version-history":[{"count":23,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/16083\/revisions"}],"predecessor-version":[{"id":125852,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/16083\/revisions\/125852"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/media?parent=16083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/categories?post=16083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/tags?post=16083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}