{"id":2219,"date":"2018-11-01T06:14:16","date_gmt":"2018-11-01T06:14:16","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=2219"},"modified":"2018-11-02T10:30:23","modified_gmt":"2018-11-02T10:30:23","slug":"use-linux-sftp-command-to-transfer-files-on-remote-servers","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/01\/use-linux-sftp-command-to-transfer-files-on-remote-servers\/","title":{"rendered":"Use Linux SFTP Command to Transfer Files on Remote Servers"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linoxide.com\/wp-content\/uploads\/2018\/10\/sftp-commands.jpg\" alt=\"sftp commands\" width=\"713\" height=\"341\" \/><\/p>\n<p>SFTP is a protocol that offers a secure and private channel for transfer of files between systems using encryption. A misconception exists about the acronym SFTP, with some thinking it stands for Secure File Transfer Protocol. It stands for SSH File Transfer Protocol. Where in &#8216;FTPS&#8217; is different, FTPS client will first check if the ftps server&#8217;s certificate is trusted and use Secure Sockets Layer protocol (TLS).<\/p>\n<p>One may be forgiven to think that SFTP and FTP are similar in terms of functionality but, the two employ varied protocols. You, therefore, cannot use a standard FTP client to connect to an SFTP server. In this guide, we will focus on the commonly used SFTP commands.<\/p>\n<p>Read Also: <a href=\"https:\/\/linoxide.com\/linux-how-to\/lftp-commands\/\" target=\"_blank\" rel=\"noopener\">12 lftp Commands to Manage Files with Examples<\/a><\/p>\n<p>The standard application of SFTP is to run on a command interface within its own environment. That is why in most cases you will notice the program interface changing to the prompt sftp&gt;. The moment you have invoked the SFTP session, the usual system commands will not execute unless you call them using a specific language that is in the SFTP command line standard.<\/p>\n<p>Not all computers can process SFTP commands. You can choose to use the graphical interface version of SFTP or the command line depending on the Operating System you are using. The GUI interface requires you to install an SFTP utility.<\/p>\n<p>In this article, we will take you through some SFTP commands examples that you can use via the unix\/linux command line.<\/p>\n<h3>How to Connect With SFTP<\/h3>\n<p>The SSH protocol used to establish communication are the same as those required by an SFTP channel. Most people prefer to use saved passwords set as defaults, but I would recommend the use of SSH keys that you can use when you need to access any system.<\/p>\n<p>To start an SFTP session, you need a username and the remote <a href=\"https:\/\/linoxide.com\/linux-command\/display-set-hostname-linux\/\" target=\"_blank\" rel=\"noopener\">hostname<\/a>. Alternatively, you can use the <a href=\"https:\/\/linoxide.com\/linux-how-to\/learn-how-get-linux-ip-address-different-ways\/\" target=\"_blank\" rel=\"noopener\">IP address<\/a> of the host name at the prompt like shown below:<\/p>\n<p>~ # sftp <a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a><br \/>\n<a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a>&#8216;s password:<br \/>\nConnected to <a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a><\/p>\n<p>In the above example, if there were a connection that allows the processing of the above command, you would expect a password prompt before gaining access.<\/p>\n<h2>1) How to Get Help at the Prompt<\/h2>\n<p>If you have no clue on the type or format that can be used on an SFTP command line, use the \u201c?\u201d or \u201chelp\u201d at the prompt as follows<\/p>\n<p>sftp ?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linoxide.com\/wp-content\/uploads\/2018\/10\/sftp.png\" alt=\"sFTP commands\" width=\"815\" height=\"575\" \/><\/p>\n<h2>2) Confirm the Working Directory<\/h2>\n<p>Using the command lpwd will give more information on the working directory. The pwd is used to check the remote working directory.<\/p>\n<p>sftp&gt; lpwd<\/p>\n<p>Output<\/p>\n<p>Local working directory: \/root<br \/>\nsftp&gt; pwd<\/p>\n<p>Output<\/p>\n<p>Remote working directory: \/upload<\/p>\n<h2>3) Listing Files<\/h2>\n<p>At the SFTP command prompt, you list both remote and local files using different commands.<\/p>\n<p>Remote listing<\/p>\n<p>sftp&gt; ls<\/p>\n<p>Local listing<\/p>\n<p>sftp&gt; lls<\/p>\n<h2>4) Uploading Files<\/h2>\n<p>Uploading can take place by placing single or multiple files on the remote host.<\/p>\n<p>Single file on the remote host use,<\/p>\n<p>sftp&gt; put Hello-World.txt<\/p>\n<p>Output<\/p>\n<p>Uploading Hello-World.txt to \/upload\/Hello-World.txt<br \/>\nHello-World.txt<\/p>\n<p>Multiple files on the remote host<\/p>\n<p>sftp&gt; mput *.txt<\/p>\n<p>Output<\/p>\n<p>Uploading Hello-World.txt to \/upload\/Hello-World.txt<br \/>\nHello-World.txt 100% 0 0.0KB\/s 00:00<br \/>\nUploading file1.txt to \/upload\/file1.txt<br \/>\nfile1.txt 100% 0 0.0KB\/s 00:00<br \/>\nUploading file2.txt to \/upload\/file2.txt<br \/>\nfile2.txt 100% 0 0.0KB\/s 00:00<br \/>\nUploading file3.txt to \/upload\/file3.txt<br \/>\nfile3.txt 100% 0 0.0KB\/s 00:00<br \/>\nUploading file4.txt to \/upload\/file4.txt<br \/>\nfile4.txt 100% 0 0.0KB\/s 00:00<\/p>\n<h2>5) Downloading Files<\/h2>\n<p>You will be able to download single or multiple files in a local-path or system.<\/p>\n<p>sftp&gt; get file1.pdf<\/p>\n<p>Output<\/p>\n<p>Fetching \/upload\/file1.pdf to file1.pdf<\/p>\n<h3>Download multiple files on a local-path or system<\/h3>\n<p>sftp&gt; mget * .pdf<\/p>\n<p>Output<\/p>\n<p>Fetching \/upload\/file1.pdf to file1.pdf<br \/>\nFetching \/upload\/file2.pdf to file2.pdf<br \/>\nFetching \/upload\/file3.pdf to file3.pdf<br \/>\nFetching \/upload\/file4.pdf to file4.pdf<br \/>\nFetching \/upload\/file5.pdf to file5.pdf<\/p>\n<p>It is evident that when downloading a file in the local system is done using the same name. When you want to use a different name on a remote file download, the name should be specified at the end of the command.<\/p>\n<h2>6) Switching Directories<\/h2>\n<p>On the remote server, you use the command,<\/p>\n<p>sftp&gt; cd test<\/p>\n<p>On the local machine, you use the command,<\/p>\n<p>sftp&gt; lcd Documents<\/p>\n<h2>7) Creating directories<\/h2>\n<p><a href=\"https:\/\/linoxide.com\/linux-command\/linux-mkdir-command\/\" target=\"_blank\" rel=\"noopener\">Creating directories<\/a> on both remote and local paths is possible<\/p>\n<p>A new directory on the local path<\/p>\n<p>sftp&gt; mkdir test<\/p>\n<p>A new directory on a remote host<\/p>\n<p>sftp&gt; lmkdir Documents<\/p>\n<h2>8) Removing Directories<\/h2>\n<p>Removing a directory or file in remote hosts<\/p>\n<p>Removing a file in remote hosts<\/p>\n<p>sftp&gt; rm Report.xls<\/p>\n<p>Removing directory in remote hosts<\/p>\n<p>sftp&gt; rmdir Department<\/p>\n<p>Note: This command will only work if the target directory is empty<\/p>\n<h2>9) Exiting the Command Shell<\/h2>\n<p>The exclamation mark! (known as a command in this case) is used to get out of the SFTP command prompt as shown in the following example.<\/p>\n<p>sftp&gt;!<\/p>\n<p>[<a href=\"\/cdn-cgi\/l\/email-protection\">[email protected]<\/a> ~]# exit<br \/>\nShell exited with status 1<br \/>\nsftp&gt;<\/p>\n<p>As simple as it may look like, SFTP is a very powerful tool used for administering servers and managing file transfers between hosts. The utility can be used on both remote and local servers.<\/p>\n<h3>Read Also:<\/h3>\n<ul>\n<li><a href=\"https:\/\/linoxide.com\/how-tos\/scp-command-file-directory-transfer-linux\/\" target=\"_blank\" rel=\"noopener\">How to Use SCP Command for A File\/Directory Transfer in Linux<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/linoxide.com\/linux-how-to\/how-transfer-files-servers-sftp-commands-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SFTP is a protocol that offers a secure and private channel for transfer of files between systems using encryption. A misconception exists about the acronym SFTP, with some thinking it stands for Secure File Transfer Protocol. It stands for SSH File Transfer Protocol. Where in &#8216;FTPS&#8217; is different, FTPS client will first check if the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/01\/use-linux-sftp-command-to-transfer-files-on-remote-servers\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Use Linux SFTP Command to Transfer Files on Remote Servers&#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-2219","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\/2219","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=2219"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2219\/revisions"}],"predecessor-version":[{"id":2389,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2219\/revisions\/2389"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}