Download file from linux to local

How to Download a File on Ubuntu Linux using the Command Line

Linux Command line offers more flexibility and control than GUI. A number of people prefer to use the command line than GUI because it is easier and quicker to use than GUI. Using the command line, it is easier to automate the tasks using one line. In addition, it utilizes fewer resources than GUI.

Downloading files is a routine task that is normally performed every day that can include file types like ZIP, TAR, ISO, PNG, etc. you can simply and quickly perform this task using the command line terminal. It requires only using your keyboard. So today, I will show you how you can download a file using the command line in Linux. There are normally two known ways to do this, that is using wget and curl utility. For this article, I am using Ubuntu 20.04 LTS for describing the procedure. But the same commands will work on other Linux distributions like Debian, Gentoo, and CentOS too.

Download files using Curl

Curl can be used to transfer data over a number of protocols. It supports many protocols including HTTP, HTTPS, FTP, TFTP, TELNET, SCP, etc. using Curl, you can download any remote files. It supports pause and resumes functions as well.

To get started with, first, you need to install the curl.

Install curl

Launch command line application in Ubuntu that is Terminal by pressing the Ctrl+Alt+T key combinations. Then enter the below command to install curl with sudo.

When prompted for a password, enter sudo password.

Once the installation is complete, enter the below command to download a file.

Download and save the file using the source file name

To save the file with the same name as the original source file on the remote server, use –O (uppercase O) followed by curl as below:

Instead of -O, you can also specify, “–remote-name” as shown below. Both work the same.

Download and save the file with a different name

If you want to download the file and save it in a different name than the name of the file in the remote server, use -o (lower-case o) as shown below. This is helpful when the remote URL doesn’t contain the file name in the URL as shown in the example below.

[filename] is the new name of the output file.

Download multiple files

To download multiple files, enter the command in the following syntax:

Download files from an FTP Server

To download a file from FTP server, enter the command in following syntax:

Читайте также:  Gpedit msc закрывается при открытии windows 10

To download files from user authenticated FTP servers, use the following syntax:

Pause and resume download

While downloading a file, you can manually pause it using Ctrl+C or sometimes it automatically gets interrupted and stopped due to any reason, you can resume it. Navigate to the same directory where you have previously downloaded the file then enter the command in the following syntax:

Download files using Wget

Using wget, you can download files and contents from Web and FTP servers. Wget is a combination of www and the get. It supports protocols like FTP, SFTP, HTTP, and HTTPS. Also it supports recursive download feature. This feature is very useful if you want to download an entire website for offline viewing or for generating a backup of a static website. In addition, you can use it to retrieve content and files from various web servers.

Install wget

Launch command line application in Ubuntu that is terminal by pressing the Ctrl+Alt+T key combinations. Then enter the below command to install wget with sudo.

When prompted for a password, enter the sudo password.

Download file or webpage using wget

To download a file or a webpage, open the Terminal and enter the command in the following syntax:

To save a single webpage, enter the command in the following syntax:

Download files with a different name

If you want to download and save the file with a different name than the name of the original remote file, use -O (upper-case O) as shown below. This is helpful especially when you are downloading a webpage that automatically get saved with the name “index.html”.

To download a file with a different name, enter the command in the following syntax:

Download files through FTP

To download a file from an FTP server, type the command in the following syntax:

To download files from user authenticated FTP servers, use the below syntax:

Recursively download files

You can use the recursive download feature to download everything under the specified directory whether a website or an FTP site. To use the recursive download feature, enter the command in the below syntax:

Download multiple files

You can use wget to download multiple files. Make a text file with a list of file URLs, then use the wget command in the following syntax to download that list.

For instance, I have the text file named “downloads.txt” in which there is a list of two URLs that I want to download using wget. You can see my text file content in the below image:

I will use the below command to download the file links contained in the text file:

You can see that it is downloading both links one by one.

Pause and Resume download

You can Press Ctrl + C to pause a download. To resume a paused download, go to the same directory where you were downloading the file previously and use –c option after wget as in the below syntax:

Using the above command, you will notice that your download has resumed from where it was paused.

So in this article, we have discussed the basic usage of two command-line methods using which you can download a file. One thing to Note that if you do not specify a directory while downloading a file, the files will be downloaded in the current directory in which you are working.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Источник

10 single line SFTP commands to transfer files in Unix/Linux

Table of Contents

SFTP stands for secure file transfer program similar to ftp. The only difference is that Unix or Linux SFTP command performs all operations over an encrypted SSH transport. It may also use many features of ssh, such as public key authentication and compression.

Читайте также:  0х80004005 windows 10 сеть

I have already written another article with the steps to setup SFTP server with passwordless login using authorized_keys in Unix and Linux. So I will use the same SFTP server to demonstrate single line SFTP commands to transfer files and directory from local to remote and remote to local server.

Some more articles on related topic to transfer files and folders between two servers:

Lab Environment

SFTP Server:
Hostname : sftp-server
IP Address : 192.168.43.83

SFTP Client:
Hostname : sftp-client
IP Address : 192.168.43.82

1. Copy file from remote server to local machine windows

We can use connect to our SFTP Server from Windows machine using any SFTP Client such as WinSCP, FileZilla etc. The SFTP syntax for destination may be specified either as [user@]host[:path] or as a URI in the form

I will use WinSCP on my Windows Laptop to connect to our Linux SFTP Server. Provide the IP Address and other User credential to login to SFTP server using WinSCP

Once connected you can now copy file from remote server to local machine windows or vice versa.

Assuming the user deepak has enough privilege you should be able to copy file from remote server to local machine windows or vice versa.

2. Single line SFTP get command to download file from remote to local server

Use below SFTP syntax to download file from remote to local server using SFTP get command.

I have dest_dir folder on sftp-server on which I will create a new file ( sftp-server_file ) and then we will download this file on sftp-client using SFTP get command.

Connect to sftp-server using sftp-client and download sftp-server_file to /tmp on sftp-client using SFTP get command.

Since I had configured passwordless sftp, we did not got any SFTP command line password prompt

3. Single line SFTP put command to upload file from local to remote server

Use below SFTP syntax with to upload file from local to remote server using SFTP put command.

I will create a file sftp-client_file under /tmp on sftp-client

Upload /tmp/sftp-client_file to sftp-server using single line SFTP put command

As you see the one line SFTP command line file upload was successful and since we are using SFTP authorized_keys, we did not got any SFTP command line password prompt

4. Single line SFTP commands to download directory from remote to local server

We will use the same SFTP syntax as we used for SFTP get command to download file from remote to local server with an additional SFTP argument

I have created sftp-server_dir on sftp-server

Next we will use single line SFTP get command line to download directory from remote to local server under /tmp

As you see the single line SFTP command line to download directory from remote to local server was successful and since we are SFTP authorized_keys, we did not got any SFTP command line password prompt.

Verify the directory on sftp-client we just downloaded under /tmp using SFTP command:

Where does SFTP download to?

In the above SFTP usage example we had explicitly provided the path to download files and directory. By default the local directory under which you have executed SFTP will be the «local path» where SFTP will by default download the files to if you have not given any source directory.

SFTP Usage Example:

Below SFTP usage example will clear your doubt on «where does sftp download to»

We have used below commands in this SFTP usage example:

5. SFTP commands to upload directory from local to remote server

I could not find a single line SFTP put command to upload directory from local to remote server, if you come across any such one liner SFTP put command do let me know via comment section

I have used an alternate approach to combine all the SFTP commands by using EOF tag.

Читайте также:  Acer aspire windows home

6. SFTP commands to transfer file using batch file

You can automate SFTP file transfer in Unix and Linux using batch file. I have explained more about batch file in another article so I will not cover this part again. use the below SFTP Syntax to use batch file and automate file transfers

I have created below SFTP batch file to upload directory ( sftp-client_dir ) from local to remote server.

This batch file will create sftp-client_dir on sftp-server and then upload directory sftp-client_sir from sftp-client to the SFTP server.

Verify if the sftp-client_dir was successfully uploaded to sftp-server . Since we have configured SFTP authorized_keys to perform passwordless sftp, did not got any SFTP command line password prompt

7. Single line SFTP commands to remove directory on remote server

The SFTP syntax to remove directory on sftp-server using one liner SFTP command line is same as we used to upload file from local to remote server

Using the below one liner SFTP rmdir command we will remove sftp-client_dir on sftp-server . Since this directory is under exchange folder of sftp-server hence I have provided this path while connecting to sftp-server .

We have successfully removed sftp-client_dir from our sftp-server which was inside exchange folder. Since we have configured SFTP authorized_keys to perform passwordless sftp, did not got any SFTP command line password prompt

8. Transfer files with SFTP commands using ssh_config

You can create a config file with SSH Client configuration values which will be used by SFTP command to transfer files. Use below SFTP syntax to use ssh_config

I have created below ssh config files with some values which will be used by our sftp-client

We will use this ssh_config file with SFTP command line in combination with -F argument as shown below

You can combine this with batch file which I used in above SFTP usage examples to automate SFTP transfer files between local and remote servers. Since we have configured SFTP authorized_keys to perform passwordless sftp, did not got any SFTP command line password prompt.

9. Use SSH options with SFTP single commands

If you do not wish to create additional SSH config file then you can also pass those arguments using -o argument with SFTP command. Use below SFTP syntax:

I have used some of the SSH client options in the below SFTP usage example to use Public Key Authentication with our SFTP.

Since we have configured SFTP authorized_keys to perform passwordless sftp, we did not got any SFTP command line password prompt

10. Use different Port with SFTP Commands to transfer files

By default SFTP uses the same port as SSH i.e. 22. But you can also configure SSH and SFTP to use a different port by using Port= in /etc/ssh/sshd_config on SFTP server. In this SFTP usage example I have setup SFTP to use port 2200 instead of port 22.

We can connect using a custom SFTP port using -o Port= as shown below

or alternatively we can also use SFTP argument -P to define a custom port for SFTP connection.

Lastly I hope the SFTP usage examples from the article to use one liner SFTP commands in Unix and Linux to transfer files was helpful. So, let me know your suggestions and feedback using the comment section.

Related Searches: linux sftp command line example, sftp get command, sftp usage, sftp syntax, sftp put command, sftp upload files, copy file from remote server to local machine windows, Where does sftp download to, sftp commands

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

Оцените статью