{"id":180,"date":"2021-07-27T05:04:17","date_gmt":"2021-07-27T05:04:17","guid":{"rendered":"https:\/\/www.cyberrafting.com\/blog\/?p=180"},"modified":"2021-07-27T05:04:18","modified_gmt":"2021-07-27T05:04:18","slug":"sftp-commands","status":"publish","type":"post","link":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/","title":{"rendered":"Sftp commands in Linux"},"content":{"rendered":"\n<p>File Transfer Protocol (FTP) was a widely used protocol for remotely transferring files or data in an unencrypted format, which is not a secure method of communication. As we all know, File Transfer Protocol is not at all secure because all transmissions occur in clear text, and the data can be read by anyone sniffing the network packets.<\/p>\n\n\n\n<p>So, in general, FTP should only be used in specific situations or on networks that you trust. SCP and SSH have addressed this security ambiguity over time, adding a secure encrypted layer while transferring data between remote computers.<\/p>\n\n\n\n<p>To establish a secure connection, SFTP (Secure File Transfer Protocol) runs over SSH protocol on standard port 22 by default. SFTP has been integrated into a number of graphical user interface (GUI) tools (FileZilla, WinSCP, FireFTP etc.).<\/p>\n\n\n\n<p>Security Caution: Please do not open the SSH port (Secure SHell) globally as this would be a security breach. You can only open for specific IP addresses from which you intend to transfer or manage files on the remote system, or vice versa.<\/p>\n\n\n\n<p>This article will walk you through ten sftp command examples to use with an interactive command-line interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">1. How to Connect to SFTP<\/span><\/strong><\/h2>\n\n\n\n<p>The same SSH protocol is used by default to authenticate and establish an SFTP connection. At the command prompt, enter the username and remote hostname or IP address to begin an SFTP session. After successful authentication, you will see a shell with an sftp&gt; prompt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@tecmint ~]# sftp tecmint@27.48.137.6\n\nConnecting to 27.48.137.6...\ntecmint@27.48.137.6's password:\nsftp&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">2. Getting Help<\/span><\/strong><\/h2>\n\n\n\n<p>When you&#8217;re in the sftp prompt, check the available commands by typing &#8216;?&#8217; or &#8216;help&#8217; into the command prompt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; ?\nAvailable commands:\ncd path                       Change remote directory to 'path'\nlcd path                      Change local directory to 'path'\nchgrp grp path                Change group of file 'path' to 'grp'\nchmod mode path               Change permissions of file 'path' to 'mode'\nchown own path                Change owner of file 'path' to 'own'\nhelp                          Display this help text\nget remote-path &#91;local-path]  Download file\nlls &#91;ls-options &#91;path]]       Display local directory listing\nln oldpath newpath            Symlink remote file\nlmkdir path                   Create local directory\nlpwd                          Print local working directory\nls &#91;path]                     Display remote directory listing\nlumask umask                  Set local umask to 'umask'\nmkdir path                    Create remote directory\nput local-path &#91;remote-path]  Upload file\npwd                           Display remote working directory\nexit                          Quit sftp\nquit                          Quit sftp\nrename oldpath newpath        Rename remote file\nrmdir path                    Remove remote directory\nrm path                       Delete remote file\nsymlink oldpath newpath       Symlink remote file\nversion                       Show SFTP version\n!command                      Execute 'command' in local shell\n!                             Escape to local shell\n?                             Synonym for help\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">3. Check Present Working Directory<\/span><\/strong><\/h2>\n\n\n\n<p>The command \u2018lpwd\u2018 is used to check the current working directory on the local machine, whereas the command \u2018pwd\u2018 is used to check the remote working directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; lpwd\nLocal working directory: \/\nsftp&gt; pwd\nRemote working directory: \/tecmint\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">4. Listing Files<\/span><\/strong><\/h2>\n\n\n\n<p>Listing files and directories on the local and remote systems.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span style=\"text-decoration: underline;\">On Remote:<\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; ls<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span style=\"text-decoration: underline;\">On Local:<\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; lls<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">5. Upload File<\/span><\/strong><\/h2>\n\n\n\n<p>Insert one or more files into the remote system.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; put local.profile\nUploading local.profile to \/tecmint\/local.profile<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">6. Upload Multiple Files<\/span><\/strong><\/h2>\n\n\n\n<p>Adding several files to the remote system.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; mput *.xls<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">6.1. Download Files<\/span><\/strong><\/h3>\n\n\n\n<p>Obtaining single or multiple files from the local system<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; get SettlementReport_1-10th.xls\nFetching \/tecmint\/SettlementReport_1-10th.xls to SettlementReport_1-10th.xls<\/code><\/pre>\n\n\n\n<p>Get access to multiple files on a local system.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; mget *.xls<\/code><\/pre>\n\n\n\n<p>Note: As we can see by default, getting a command downloads a file with the same name in the local system. We can download a remote file with a different name by including it at the end of the URL. (This only applies when downloading a single file.)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">7. Switching Directories<\/span><\/strong><\/h2>\n\n\n\n<p>Transferring files from one directory to another in both local and remote locations.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span style=\"text-decoration: underline;\">On Remote:<\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; cd test\nsftp&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span style=\"text-decoration: underline;\">On Local:<\/span><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; lcd Documents<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\"><strong>8. Create Directories<\/strong><\/span><\/h2>\n\n\n\n<p>Making new directories in both local and remote areas.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; mkdir test\nsftp&gt; lmkdir Documents<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">9. Remove Directories<\/span><\/strong><\/h2>\n\n\n\n<p>Remove the remote system&#8217;s directory or file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; rm Report.xls\nsftp&gt; rmdir sub1<\/code><\/pre>\n\n\n\n<p>Please keep in mind that in order to remove or delete a directory from a remote location, the directory must be empty.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">10. Exit sFTP Shell<\/span><\/strong><\/h2>\n\n\n\n<p>The \u2018!&#8217; command takes us to a local shell where we can run Linux commands. Where we can see sftp&gt; prompt return, type the command \u2018exit\u2018.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sftp&gt; !\n\n&#91;root@sftp ~]# exit\nShell exited with status 1\nsftp&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><span style=\"text-decoration: underline;\">Conclusion<\/span><\/strong><\/h2>\n\n\n\n<p>The SFTP protocol is a very useful tool for managing servers and transferring files to and from them (Local and Remote). We hope that these tutorials have helped you understand how to use SFTP to some extent.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>File Transfer Protocol (FTP) was a widely used protocol for remotely transferring files or data in an unencrypted format, which is not a secure method &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sftp commands in Linux<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sftp commands in Linux\" \/>\n<meta property=\"og:description\" content=\"File Transfer Protocol (FTP) was a widely used protocol for remotely transferring files or data in an unencrypted format, which is not a secure method &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Cyber Rafting\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-27T05:04:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-27T05:04:18+00:00\" \/>\n<meta name=\"author\" content=\"cyberrafting\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cyberrafting\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/\"},\"author\":{\"name\":\"cyberrafting\",\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/#\\\/schema\\\/person\\\/0533280d6685c57435a3151c387fff99\"},\"headline\":\"Sftp commands in Linux\",\"datePublished\":\"2021-07-27T05:04:17+00:00\",\"dateModified\":\"2021-07-27T05:04:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/\"},\"wordCount\":533,\"commentCount\":0,\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/\",\"url\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/\",\"name\":\"Sftp commands in Linux\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/#website\"},\"datePublished\":\"2021-07-27T05:04:17+00:00\",\"dateModified\":\"2021-07-27T05:04:18+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/#\\\/schema\\\/person\\\/0533280d6685c57435a3151c387fff99\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/linux\\\/sftp-commands\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sftp commands in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/\",\"name\":\"Cyber Rafting Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.cyberrafting.com\\\/blog\\\/#\\\/schema\\\/person\\\/0533280d6685c57435a3151c387fff99\",\"name\":\"cyberrafting\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c1f1c30a5a84d51fe015a59038822cd67358fd7fa1e202f74b946af36798f286?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c1f1c30a5a84d51fe015a59038822cd67358fd7fa1e202f74b946af36798f286?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c1f1c30a5a84d51fe015a59038822cd67358fd7fa1e202f74b946af36798f286?s=96&d=mm&r=g\",\"caption\":\"cyberrafting\"},\"sameAs\":[\"https:\\\/\\\/www.cyberrafting.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sftp commands in Linux","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/","og_locale":"en_US","og_type":"article","og_title":"Sftp commands in Linux","og_description":"File Transfer Protocol (FTP) was a widely used protocol for remotely transferring files or data in an unencrypted format, which is not a secure method &hellip;","og_url":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/","og_site_name":"Cyber Rafting","article_published_time":"2021-07-27T05:04:17+00:00","article_modified_time":"2021-07-27T05:04:18+00:00","author":"cyberrafting","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cyberrafting","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/#article","isPartOf":{"@id":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/"},"author":{"name":"cyberrafting","@id":"https:\/\/www.cyberrafting.com\/blog\/#\/schema\/person\/0533280d6685c57435a3151c387fff99"},"headline":"Sftp commands in Linux","datePublished":"2021-07-27T05:04:17+00:00","dateModified":"2021-07-27T05:04:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/"},"wordCount":533,"commentCount":0,"articleSection":["Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/","url":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/","name":"Sftp commands in Linux","isPartOf":{"@id":"https:\/\/www.cyberrafting.com\/blog\/#website"},"datePublished":"2021-07-27T05:04:17+00:00","dateModified":"2021-07-27T05:04:18+00:00","author":{"@id":"https:\/\/www.cyberrafting.com\/blog\/#\/schema\/person\/0533280d6685c57435a3151c387fff99"},"breadcrumb":{"@id":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.cyberrafting.com\/blog\/linux\/sftp-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cyberrafting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Sftp commands in Linux"}]},{"@type":"WebSite","@id":"https:\/\/www.cyberrafting.com\/blog\/#website","url":"https:\/\/www.cyberrafting.com\/blog\/","name":"Cyber Rafting Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cyberrafting.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.cyberrafting.com\/blog\/#\/schema\/person\/0533280d6685c57435a3151c387fff99","name":"cyberrafting","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c1f1c30a5a84d51fe015a59038822cd67358fd7fa1e202f74b946af36798f286?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c1f1c30a5a84d51fe015a59038822cd67358fd7fa1e202f74b946af36798f286?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c1f1c30a5a84d51fe015a59038822cd67358fd7fa1e202f74b946af36798f286?s=96&d=mm&r=g","caption":"cyberrafting"},"sameAs":["https:\/\/www.cyberrafting.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/comments?post=180"}],"version-history":[{"count":1,"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/posts\/180\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberrafting.com\/blog\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}