{"id":11358,"date":"2019-03-13T07:11:50","date_gmt":"2019-03-13T07:11:50","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11358"},"modified":"2019-03-13T07:11:50","modified_gmt":"2019-03-13T07:11:50","slug":"10-sftp-command-examples-to-transfer-files-on-remote-servers-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/10-sftp-command-examples-to-transfer-files-on-remote-servers-in-linux\/","title":{"rendered":"10 sFTP Command Examples to Transfer Files on Remote Servers in Linux"},"content":{"rendered":"<p><strong>File Transfer Protocol<\/strong>\u00a0(<strong>FTP<\/strong>) was widely used protocol to transfer files or data remotely in unencrypted format which is not secure way to communicate. As we all know that\u00a0<strong>File Transfer Protocol<\/strong>\u00a0is not at all secure because all transmissions happens in clear text and the data can be readable by anyone during sniffing the packets on the network.<\/p>\n<div id=\"attachment_5520\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/02\/sftp-commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5520\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/02\/sftp-commands.png\" alt=\"sftp commands\" width=\"442\" height=\"289\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">10 sftp command examples<\/p>\n<\/div>\n<p>So, basically FTP can be used in limited cases or on the networks that you trust. Over the period of time\u00a0<a title=\"scp linux commands\" href=\"https:\/\/www.tecmint.com\/scp-commands-examples\/\" target=\"_blank\" rel=\"noopener\">SCP<\/a>and SSH addresses this security ambiguity and added an encrypted secure layer while transferring data between remote computers.<\/p>\n<p><strong>SFTP<\/strong>\u00a0(<strong>Secure File Transfer Protocol<\/strong>) runs over\u00a0<strong>SSH<\/strong>\u00a0protocol on standard port\u00a0<strong>22<\/strong>\u00a0by default to establish a secure connection.\u00a0<strong>SFTP<\/strong>\u00a0has been integrated into many\u00a0<strong>GUI<\/strong>\u00a0tools (<strong>FileZilla<\/strong>,\u00a0<strong>WinSCP<\/strong>,\u00a0<strong>FireFTP<\/strong>\u00a0etc.).<\/p>\n<p><strong>Security Warnings<\/strong>: Please don\u2019t open\u00a0<strong>SSH<\/strong>\u00a0port (<strong>Secure SHell<\/strong>) globally as this would be a security breaches. You can only open for specific IP from where you are going to transfer or manage files on remote system or vice versa.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/5-best-practices-to-secure-and-protect-ssh-server\/\" target=\"_blank\" rel=\"noopener\">5 Best Practices to Secure and Protect SSH Server<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">10 Wget Command Examples in Linux<\/a><\/li>\n<\/ol>\n<p>This article will guide you\u00a0<strong>10 sftp command examples<\/strong>\u00a0to use it through interactive command-line interface.<\/p>\n<h3>1. How to Connect to SFTP<\/h3>\n<p>By default, same SSH protocol is used to authenticate and establish a SFTP connection. To start an SFTP session, enter the username and remote hostname or IP address at the command prompt. Once authentication successful, you will see a shell with an\u00a0<strong>sftp&gt;<\/strong>\u00a0prompt.<\/p>\n<pre>[root@tecmint ~]# sftp tecmint@27.48.137.6\r\n\r\nConnecting to 27.48.137.6...\r\ntecmint@27.48.137.6's password:\r\n<strong>sftp&gt;<\/strong><\/pre>\n<h3>2. Getting Help<\/h3>\n<p>Once, you in the\u00a0<strong>sftp prompt<\/strong>, check the available commands by typing \u2018<strong>?<\/strong>\u2018 or \u2018<strong>help<\/strong>\u2018 at command prompt.<\/p>\n<pre>sftp&gt; ?\r\nAvailable commands:\r\ncd path                       Change remote directory to 'path'\r\nlcd path                      Change local directory to 'path'\r\nchgrp grp path                Change group of file 'path' to 'grp'\r\nchmod mode path               Change permissions of file 'path' to 'mode'\r\nchown own path                Change owner of file 'path' to 'own'\r\nhelp                          Display this help text\r\nget remote-path [local-path]  Download file\r\nlls [ls-options [path]]       Display local directory listing\r\nln oldpath newpath            Symlink remote file\r\nlmkdir path                   Create local directory\r\nlpwd                          Print local working directory\r\nls [path]                     Display remote directory listing\r\nlumask umask                  Set local umask to 'umask'\r\nmkdir path                    Create remote directory\r\nput local-path [remote-path]  Upload file\r\npwd                           Display remote working directory\r\nexit                          Quit sftp\r\nquit                          Quit sftp\r\nrename oldpath newpath        Rename remote file\r\nrmdir path                    Remove remote directory\r\nrm path                       Delete remote file\r\nsymlink oldpath newpath       Symlink remote file\r\nversion                       Show SFTP version\r\n!command                      Execute 'command' in local shell\r\n!                             Escape to local shell\r\n?                             Synonym for help<\/pre>\n<h3>3. Check Present Working Directory<\/h3>\n<p>The command \u2018<strong>lpwd<\/strong>\u2018 is used to check the\u00a0<strong>Local<\/strong>\u00a0present working directory, whereas \u2018<strong>pwd<\/strong>\u2018 command is used to check\u00a0<strong>Remote<\/strong>\u00a0working directory.<\/p>\n<pre>sftp&gt; lpwd\r\nLocal working directory: \/\r\nsftp&gt; pwd\r\nRemote working directory: \/tecmint\/<\/pre>\n<ol>\n<li><strong>lpwd<\/strong>\u00a0\u2013 print the current directory on your system<\/li>\n<li><strong>pwd<\/strong>\u00a0\u2013 print the current directory on the ftp server<\/li>\n<\/ol>\n<h3>4. Listing Files<\/h3>\n<p>Listing files and directories in local as well as remote system.<\/p>\n<h5>On Remote<\/h5>\n<pre>sftp&gt; ls<\/pre>\n<h5>On Local<\/h5>\n<pre>sftp&gt; lls<\/pre>\n<h3>5. Upload File<\/h3>\n<p>Put single or multiple files in remote system.<\/p>\n<pre>sftp&gt; put local.profile\r\nUploading local.profile to \/tecmint\/local.profile<\/pre>\n<h3>6. Upload Mutiple Files<\/h3>\n<p>Putting multiple files on in remote system.<\/p>\n<pre>sftp&gt; mput *.xls<\/pre>\n<h3>6. Download Files<\/h3>\n<p>Getting single or multiple files in local system.<\/p>\n<pre>sftp&gt; get SettlementReport_1-10th.xls\r\nFetching \/tecmint\/SettlementReport_1-10th.xls to SettlementReport_1-10th.xls<\/pre>\n<p>Get multiple files on a local system.<\/p>\n<pre>sftp&gt; mget *.xls<\/pre>\n<p><strong>Note<\/strong>: As we can see by default with\u00a0<strong>get command<\/strong>\u00a0download file in local system with same name. We can download remote file with different name specifying the name at the end. (This applies only while downloading single file).<\/p>\n<h3>7. Switching Directories<\/h3>\n<p>Switching from one directory to another directory in local and remote locations.<\/p>\n<h5>On Remote<\/h5>\n<pre>sftp&gt; cd test\r\nsftp&gt;<\/pre>\n<h5>On Local<\/h5>\n<pre>sftp&gt; lcd Documents<\/pre>\n<h3>8. Create Directories<\/h3>\n<p>Creating new directories on local and remote locations.<\/p>\n<pre>sftp&gt; mkdir test<\/pre>\n<pre>sftp&gt; lmkdir Documents<\/pre>\n<h3>9. Remove Directories<\/h3>\n<p>Remove directory or file in remote system.<\/p>\n<pre>sftp&gt; rm Report.xls<\/pre>\n<pre>sftp&gt; rmdir sub1<\/pre>\n<p><strong>Note<\/strong>: To remove\/delete any directory from remote location, the directory must be empty.<\/p>\n<h3>10. Exit sFTP Shell<\/h3>\n<p>The \u2018<strong>!<\/strong>\u2018 command drop us in local shell from where we can execute Linux commands. Type \u2018<strong>exit<\/strong>\u2018 command where we can see\u00a0<strong>sftp&gt;<\/strong>\u00a0prompt return.<\/p>\n<pre>sftp&gt; !\r\n\r\n[root@sftp ~]# exit\r\nShell exited with status 1\r\nsftp&gt;<\/pre>\n<h3>Conclusion<\/h3>\n<p>The\u00a0<strong>SFTP<\/strong>\u00a0is a very useful tool for administrating servers and transferring files to and from (<strong>Local<\/strong>\u00a0and\u00a0<strong>Remote<\/strong>). We hope this tuts will help you to understand the usage of\u00a0<strong>SFTP<\/strong>\u00a0in some extent.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/sftp-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>File Transfer Protocol\u00a0(FTP) was widely used protocol to transfer files or data remotely in unencrypted format which is not secure way to communicate. As we all know that\u00a0File Transfer Protocol\u00a0is not at all secure because all transmissions happens in clear text and the data can be readable by anyone during sniffing the packets on the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/10-sftp-command-examples-to-transfer-files-on-remote-servers-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 sFTP Command Examples to Transfer Files on Remote Servers in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11358","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11358"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11358\/revisions"}],"predecessor-version":[{"id":11359,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11358\/revisions\/11359"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}