Linux Command Line Ftp to Server With Password and Upload File

Stylized Linux terminal prompt
Fatmawati Achmad Zaenuri/Shutterstock.com

The File Transfer Protocol is older than most of our readers, but it's still going strong. FTP doesn't accept the security of a modern protocol, just you may demand to use it anyway. Here's how to do it.

Warning: Don't Use FTP Over the Internet

Let's make this clear right from the outset: The File Transfer Protocol (FTP) dates back to the early 1970s and was written without any regard to security. It does not use encryption for anything. Login credentials like your username and countersign, likewise every bit the data you download or upload, are transferred in articulate text. Anyone along the mode can view your secrets. However, FTP still has its uses.

If y'all're transferring files inside your network, you should be safe–equally long every bit no ane on the network is packet-sniffing and eavesdropping on any sensitive documents as yous transfer them. If your files aren't confidential or sensitive in whatsoever fashion, moving them around your internal network with FTP should be fine. Linux has the standard ftp control line programme to deal with precisely that scenario.

Only definitely don't employ theftp command to access external resources across the net. For that, use the sftp command line plan, which uses the secure SSH File Transfer Protocol. We'll introduce both of these programs in this tutorial.

To clarify just why yous never desire to use FTP over the Internet, accept a wait at the below screenshot. It shows the FTP password in plaintext. Anyone on your network or between y'all and the FTP server on the Internet can easily come across the password is "MySecretPassword."

Without the encryption, a malicious actor could modify files you're downloading or uploading in transit, as well.

Network packet trace with clear text password

The ftp Command

Bold y'all have a valid account on an FTP site, y'all can connect to it with the following control. Throughout this commodity, substitute the IP address in the commands with the IP address of the FTP server y'all're connecting to.

ftp  192.168.iv.25

Alert: You should just utilize the ftp command to connect to servers on a trusted local network. Use the sftp command, covered below, for transferring files over the cyberspace.

The FTP server responds with a welcome message. The wording of the greeting volition vary from server to server. It and so asks for the username of the account you are logging into.

Observe that the IP  address of the site y'all're connecting to is displayed, followed by your Linux user proper name. If your account name on the FTP server is the same every bit your Linux user name, simply press the Enter key. This will use your Linux user name as the account proper noun on the FTP server. If your Linux user proper name and the FTP account name are unlike, blazon in the FTP account user name and then press Enter.

Logging In to the FTP Server

You lot will be prompted to enter your password for the FTP site. Enter your password and press Enter. Your password is non displayed on the screen. If your FTP user account proper name and countersign combination are verified by the FTP server, you are then logged into the FTP server.

You will be presented with the ftp> prompt.

Looking Around and Retrieving Files

Outset, yous'll probably desire to get a listing of the files on the FTP server. The ls command does just that. Our user sees the file gc.c is on the FTP server, and he wants to download it to his ain reckoner. His estimator is the "local estimator" in FTP parlance.

The command to recollect (or "get") a file is become.  Our user, therefore, issues the command get gc.c. They type get, a infinite, and then the proper name of the file they wish to call back.

The FTP server responds past transferring the file to the local computer and confirming the transfer took identify. The size of the file and the fourth dimension it took to transfer are likewise shown.

ls
get gc.c

To think multiple files at once, use themget (multiple get) control. The mget command volition ask y'all to ostend whether y'all want to download each file in turn. Respond by pressing "y" for yeah and "due north" for no.

This would exist dull for a great number of files. Because of this, collections of related files are ordinarily stored on ftp sites as single tar.gz or tar.bz2 files.

RELATED: How to Extract Files From a .tar.gz or .tar.bz2 File on Linux

mget *.c

Uploading Files to the FTP Server

Depending on the permissions that have been granted to your FTP account you lot might be able to upload (or "put") files to the server. To upload a file, use the put command. In our example, the user is uploading a file called Songs.tar.gz to the FTP server.

put Songs.tar.gz

Every bit you probably look, there is a control to put multiple files to the FTP server at one time. It is called mput (multiple put). Just like the mget command did, mput will ask for a "y" or "n" confirmation for the uploading of each file, one past one.

The same statement for putting sets of files into tar athenaeum applies for putting files equally it does for getting files. Our user is uploading multiple ".odt" files with the following command:

mput *.odt

Creating and Irresolute Directories

If your user account on the ftp server permits it, you lot may exist able to create directories. The command to practise this is mkdir . To exist articulate, any directory you create with the mkdir command will exist created on the ftp server and not on your local computer.

To change directories on the ftp server, use the cd command. When you use the cd command the ftp> prompt volition non change to reflect your new electric current directory. The pwd (print working directory) control will show you your current directory.

Our ftp user creates a directory called music, changes into that new directory, confirms where they are past using the pwd command and so uploads a file to that directory.

mkdir music
cd music
pwd
put songs.tar.gz

To quickly moved to the parent directory of the current directory employ the cdup command.

cdup

cdup command in a terminal widnowindow

Accessing the Local Computer

To change the directory on the local calculator, you can employ the lcd command at the ftp> prompt. It is, yet, easy to lose track of where you lot are in the local filesystem. A more convenient method of accessing the local filesystem is to use the ! control.

The ! command opens a shell window to the local computer. Yous tin do anything in this shell that you tin can in a standard terminal window. When you type leave you lot are returned to the ftp> prompt.

Our user has used the ! command and entered a shell window on the local computer. They take issued an ls control to run into what files are present in that directory then typed exit to return to the ftp> prompt.

!
ls
exit

Renaming Files

To rename files on the FTP server use the rename command. Hither our FTP user renames a file with rename so uses the ls command to list the files in the directory.

rename songs.tar.gz rock_songs.tar.gz
ls

rename command in the terminal window

Deleting Files

To delete files on the FTP server use the delete command. To delete several files at once, utilize the mdelete command. Yous will be asked to provide a "y" or "n" confirmation for the deletion of each file.

Here our FTP user has listed the files to see their names and and so chosen 1 to delete. They then make up one's mind to delete them all.

ls
delete gc.o
mdelete *.o

Using the sftp Control

Readers familiar with the IP addressing arrangement will have noticed that the 192.168 accost of the FTP server used in the higher up examples is an internal IP address, besides called a private IP address. As we warned at the commencement of this article, the ftp control should only be used on internal networks.

If you lot want to connect to a remote or public FTP server use the sftp control. Our user is going to connect to an SFTP account called demo on the publicly attainable FTP server located at examination.trebex.net.

When they connect, they are informed that the connection has been established. They are also informed that the actuality of the host cannot be verified. This is normal for the kickoff connectedness a new host. They printing "y" to accept the connection.

Considering the user account proper noun (demo) was passed on the command line they are not prompted for the user business relationship proper noun. They are prompted only for the password. This is entered, verified and accepted, and they are presented with the sftp> prompt.

sftp demo@test.rebex.cyberspace

The FTP commands we take described above will piece of work just the same in an SFTP session, with the following exceptions.

  • To delete a file apply rm (FTP uses delete)
  • To delete multiple files use rm (FTP uses mdelete)
  • To move to the parent directory utilize cd .. (FTP uses cdup)

Our user has used a few commands in their SFTP session. They have use ls to list the files, and cd to change into the pub directory. They accept used the pwd to print the working directory.

sftp commands in a terminalwindow

There are other options to transfer files in the Linux earth, notably scp (secure copy), but nosotros've focused on FTP and SFTP here. Used in the applicable scenarios these 2 commands will serve you and your file storage and retrieval needs well.

westocan1961.blogspot.com

Source: https://www.howtogeek.com/412626/how-to-use-the-ftp-command-on-linux/

0 Response to "Linux Command Line Ftp to Server With Password and Upload File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel