How to Use the FTP Command on Linux

Trending 3 months ago

Key Takeaways

  • FTP is an outdated protocol that lacks information measures, making it unsafe to usage complete nan internet. Use it only for record transfers wrong a trusted section network.
  • When utilizing FTP, beryllium alert that login credentials and nan information transferred are transmitted successful clear text.
  • For unafraid record transfers complete nan internet, usage nan sftp bid statement program, which utilizes nan SSH File Transfer Protocol and provides encryption to protect delicate information.

The File Transfer Protocol is older than astir of our readers, but it's still going strong. FTP doesn't person nan information of a modern protocol, but you whitethorn request to usage it anyway. Here's really to do it.

Warning: Don't Use FTP Over nan Internet

Let's make this clear correct from nan outset: The File Transfer Protocol (FTP) dates backmost to nan early 1970s and was written without immoderate respect to security. It does not usage encryption for anything. Login credentials for illustration your username and password, arsenic good arsenic nan information you download aliases upload, are transferred successful clear text. Anyone on nan measurement tin position your secrets. However, FTP still has its uses.

If you're transferring files wrong your network, you should beryllium safe — arsenic agelong arsenic nary 1 connected nan web is packet-sniffing and eavesdropping connected immoderate delicate documents arsenic you transportation them. If your files aren't confidential aliases delicate successful immoderate way, moving them astir your soul web pinch FTP should beryllium fine. Linux has nan modular ftp command statement program to woody pinch precisely that scenario.

But decidedly don't usage nan ftp bid to entree outer resources crossed nan internet. For that, usage nan sftp command statement program, which uses nan unafraid SSH File Transfer Protocol. We'll present some of these programs successful this tutorial.

To explain conscionable why you ne'er want to usage FTP complete nan Internet, return a look astatine nan beneath screenshot. It shows nan FTP password successful plaintext. Anyone connected your web aliases betwixt you and nan FTP server connected nan Internet tin easy spot nan password is "MySecretPassword."

Without nan encryption, a malicious character could modify files you're downloading aliases uploading successful transit, too.

Network packet trace pinch clear matter password

How to Use The ftp Command

Assuming you person a valid relationship connected an FTP site, you tin link to it pinch nan pursuing command. Throughout this article, substitute nan IP reside successful nan commands pinch nan IP reside of nan FTP server you're connecting to.

ftp 192.168.4.25

You should only usage nan ftp bid to link to servers connected a trusted section network. Use nan sftp command, covered below, for transferring files complete nan internet.

ftp relationship bid successful a terminal window

The FTP server responds pinch a invited message. The wording of nan greeting will alteration from server to server. It past asks for nan username of nan relationship you are logging into.

Notice that nan IP reside of nan tract you're connecting to is displayed, followed by your Linux personification name. If your relationship sanction connected nan FTP server is nan aforesaid arsenic your Linux personification name, simply property nan Enter key. This will usage your Linux personification sanction arsenic nan relationship sanction connected nan FTP server. If your Linux personification sanction and nan FTP relationship sanction are different, type successful nan FTP relationship personification sanction and past property Enter.

Logging In to nan FTP Server

You will beryllium prompted to participate your password for nan FTP site. Enter your password and property Enter. Your password is not displayed connected nan screen. If your FTP personification relationship sanction and password operation are verified by nan FTP server, you are past logged into nan FTP server.

You will beryllium presented pinch nan ftp> prompt.

logged successful ftp relationship successful a terminal window

Looking Around and Retrieving Files

First, you'll astir apt want to get a listing of nan files connected nan FTP server. The ls bid does conscionable that. Our personification sees nan record gc.c is connected nan FTP server, and he wants to download it to his ain computer. His machine is nan "local computer" successful FTP parlance.

The bid to retrieve (or "get") a record is get. Our user, therefore, issues nan bid get gc.c. They type get, a space, and past nan sanction of nan record they wish to retrieve.

The FTP server responds by transferring nan record to nan section machine and confirming nan transportation took place. The size of nan record and nan clip it took to transportation are besides shown.

ls get gc.c
ftp record transportation successful a terminal window

To retrieve aggregate files astatine once, usage nan mget (multiple get) command. The mget bid will inquire you to corroborate whether you want to download each record successful turn. Respond by pressing "y" for yes and "n" for no.

This would beryllium tedious for a awesome number of files. Because of this, collections of related files are usually stored connected ftp sites arsenic azygous tar.gz aliases tar.bz2 files.

mget *.c
mget bid successful a terminal window

Uploading Files to nan FTP Server

Depending connected nan permissions that person been granted to your FTP relationship you mightiness beryllium capable to upload (or "put") files to nan server. To upload a file, usage nan put command. In our example, nan personification is uploading a record called Songs.tar.gz to nan FTP server.

put Songs.tar.gz
put bid successful a terminal window

As you astir apt expect, location is simply a bid to put aggregate files to nan FTP server astatine once. It is called mput (multiple put). Just for illustration nan mget bid did, mput will inquire for a "y" aliases "n" confirmation for nan uploading of each file, 1 by one.

The aforesaid statement for putting sets of files into tar archives applies for putting files arsenic it does for getting files. Our personification is uploading aggregate ".odt" files pinch nan pursuing command:

mput *.odt
mput bid successful a terminal window

Creating and Changing Directories pinch FTP

If your personification relationship connected nan ftp server permits it, you whitethorn beryllium capable to create directories. The bid to do this is mkdir . To beryllium clear, immoderate directory you create pinch nan mkdir bid will beryllium created connected nan ftp server and not connected your section computer.

To alteration directories connected nan ftp server, usage nan cd command. When you usage nan cd bid nan ftp> punctual will not alteration to bespeak your caller existent directory. The pwd (print moving directory) bid will show you your existent directory.

Our ftp personification creates a directory called music, changes into that caller directory, confirms wherever they are by utilizing nan pwd bid past uploads a record to that directory.

mkdir music cd music pwd put songs.tar.gz
cd pwd and mkdir commands successful a terminal window

To quickly moved to nan genitor directory of nan existent directory usage nan cdup command.

cdup
cdup bid successful a terminal widnowindow

Accessing nan Local Computer successful in FTP

To alteration nan directory connected nan section computer, you tin usage nan lcd bid astatine nan ftp> prompt. It is, however, easy to suffer way of wherever you are successful nan section filesystem. A much convenient method of accessing nan section filesystem is to usage nan ! command.

The ! bid opens a ammunition model to nan section computer. You tin do thing successful this ammunition that you tin successful a modular terminal window. When you type exit you are returned to nan ftp> prompt.

Our personification has utilized nan ! bid and entered a ammunition model connected nan section computer. They person issued an ls bid to spot what files are coming successful that directory and past typed exit to return to nan ftp> prompt.

! ls exit
! ammunition bid successful a terminal window

Renaming Files pinch FTP

To rename files connected nan FTP server usage nan rename command. Here our FTP personification renames a record pinch rename and past uses nan ls bid to database nan files successful nan directory.

rename songs.tar.gz rock_songs.tar.gz ls
rename bid successful nan terminal window

Deleting Files utilizing FTP

To delete files connected nan FTP server usage nan delete command. To delete respective files astatine once, usage nan mdelete command. You will beryllium asked to supply a "y" aliases "n" confirmation for nan deletion of each file.

Here our FTP personification has listed nan files to spot their names and past chosen 1 to delete. They past determine to delete them all.

ls delete gc.o mdelete *.o
ls delete and mdelete commands successful a terminal window

Using nan sftp Command

Readers acquainted pinch nan IP addressing strategy will person noticed that nan 192.168 reside of nan FTP server utilized successful nan supra examples is an soul IP address, besides called a backstage IP address. As we warned astatine nan opening of this article, nan ftp bid should only beryllium utilized connected soul networks.

If you want to link to a distant aliases nationalist FTP server usage nan sftp command. Our personification is going to link to an SFTP relationship called demo connected nan publically accessible FTP server located astatine test.trebex.net.

When they connect, they are informed that nan relationship has been established. They are besides informed that nan authenticity of nan big cannot beryllium verified. This is normal for nan first relationship a caller host. They property "y" to judge nan connection.

Because nan personification relationship sanction (demo) was passed connected nan bid statement they are not prompted for nan personification relationship name. They are prompted only for nan password. This is entered, verified and accepted, and they are presented pinch nan sftp> prompt.

sftp [email protected]
connecting to an sftp tract successful a terminal window

The FTP commands we person described supra will activity conscionable nan aforesaid successful an SFTP session, pinch nan pursuing exceptions.

  • To delete a record usage rm (FTP uses delete)
  • To delete aggregate files usage rm (FTP uses mdelete)
  • To move to nan genitor directory usage cd .. (FTP uses cdup)

Our personification has utilized a fewer commands successful their SFTP session. They person usage ls to database nan files, and cd to alteration into nan pub directory. They person utilized nan pwd to people nan moving directory.

sftp commands successful a terminalwindow

There are different options to transportation files successful nan Linux world, notably scp (secure copy), but we've focused connected FTP and SFTP here. Used successful nan applicable scenarios these 2 commands will service you and your record retention and retrieval needs well.

Source Tutorials
Tutorials