Linux commands ftp files

How to Use Linux FTP Command to Transfer Files

FTP (File Transfer Protocol) is a standard network protocol used to transfer files to and from a remote network.

In this tutorial, we will show you how to use the Linux ftp command through practical examples.

In most cases, you will use a desktop FTP client to connect to the remote server and download or upload files. However, the ftp command is useful when you work on a server without GUI and you want to transfer files over FTP to or from a remote server.

Before You Begin #

FTP traffic is not encrypted. For a secure data transfer, use SCP or SFTP .

To be able to transfer files, you must have at least read permissions on the source file and write permission on the target system.

When transferring large files it is recommended to run the ftp command inside a screen or tmux session.

The directory from where you run the ftp command is the local working directory.

Establishing an FTP Connection #

  1. To open an ftp connection to a remote system, invoke the ftp command followed by the remote server IP address or domain name. For example, to connect to an FTP server at “192.168.42.77” you would type:
220---------- Welcome to Pure-FTPd [privsep] [TLS] ---------- 220-You are user number 1 of 50 allowed. 220-Local time is now 21:35. Server port: 21. 220-This is a private system - No anonymous login 220-IPv6 connections are also welcome on this server. 220 You will be disconnected after 15 minutes of inactivity. Name (192.168.42.77:localuser): linuxize
You may see a different confirmation message depending on the FTP service running on the remote server. 
230 OK. Current restricted directory is / Remote system type is UNIX. Using binary mode to transfer files. ftp>

If the FTP server you are accessing accepts anonymous FTP accounts, and you want to log in as an anonymous user, use anonymous as username and your email address as a password.

Common FTP Commands #

Most of the FTP commands are similar or identical to the commands you would type in the Linux shell prompt.

Below are some of the most common FTP commands

  • help or ? — list all available FTP commands.
  • cd — change directory on the remote machine.
  • lcd — change directory on the local machine.
  • ls — list the names of the files and directories in the current remote directory.
  • mkdir — create a new directory within the current remote directory.
  • pwd — print the current working directory on the remote machine.
  • delete — remove a file in the current remote directory.
  • rmdir — remove a directory in the current remote directory.
  • get — copy one file from the remote to the local machine.
  • mget — copy multiple files from the remote to the local machine.
  • put — copy one file from the local to the remote machine.
  • mput — copy multiple files from the local to the remote machine.
Читайте также:  Найти папку пользователя linux

Downloading Files with the ftp Command #

Once you are logged in, your current working directory is the remote user home directory.

When downloading files with the ftp command, the files will be downloaded to the directory from which you typed the ftp command.

If you want to download the files to another local directory, switch to it by using the lcd command.

Let’s say we want to download the files to the ~/ftp_downloads directory:

To download a single file from the remote server, use the get command. For example, to download a file named backup.zip you would use the following command:

The output should look something like this:

200 PORT command successful 150-Connecting to port 60609 150 6516.9 kbytes to download 226-File successfully transferred 226 2.356 seconds (measured here), 2.70 Mbytes per second 6673256 bytes received in 2.55 seconds (2.49 Mbytes/s) 

To download multiple files at once, use the mget command. You can provide a list of individual file names or use wildcard characters:

mget backup1.zip backup2.zip

When downloading multiple files you will be prompted for confirmation for each file.

mget backup1.zip? y 200 PORT command successful 150 Connecting to port 52231 226-File successfully transferred 226 0.000 seconds (measured here), 31.51 Kbytes per second 14 bytes received in 0.00058 seconds (23.6 kbytes/s) mget backup2.zip? y 200 PORT command successful 150-Connecting to port 59179 150 7.2 kbytes to download 226-File successfully transferred 226 0.000 seconds (measured here), 16.68 Mbytes per second 7415 bytes received in 0.011 seconds (661 kbytes/s) 

Once you are done downloading files from the remote FTP server, close the connection using either the bye or quit command:

221-Goodbye. You uploaded 0 and downloaded 6544 kbytes. 221 Logout. 

Uploading Files with the FTP Command #

To upload a file from a local directory to a remote FTP server, use the put command:

The output should look something like this:

200 PORT command successful 150 Connecting to port 34583 226-File successfully transferred 226 0.849 seconds (measured here), 111.48 Kbytes per second 96936 bytes sent in 0.421 seconds (225 kbytes/s) 

If you want to upload a file that is not in your current working directory, use the absolute path to the file.

To upload multiple files from a local directory to a remote FTP server, invoke the mput command:

mput image1.jpg? y 200 PORT command successful 150 Connecting to port 41075 226-File successfully transferred 226 1.439 seconds (measured here), 102.89 Kbytes per second 151586 bytes sent in 1.07 seconds (138 kbytes/s) mput image2.jpg? y 200 PORT command successful 150 Connecting to port 40759 226-File successfully transferred 226 1.727 seconds (measured here), 111.75 Kbytes per second 197565 bytes sent in 1.39 seconds (138 kbytes/s) 

When uploading multiple files, the command will prompt you to confirm each file you want to upload.

Once you are done uploading files to your remote FTP server close the connection with bye or quit .

Conclusion #

In this tutorial, you learned how to use the ftp command to download and upload files to your remote FTP server.

Feel free to leave a comment if you have any questions.

Источник

How to Use the Linux ftp Command

FTP (File Transfer Protocol) is a network protocol used for transferring files from one computer system to another. Even though the safety of FTP tends to spark a lot of discussion, it is still an effective method of transferring files within a secure network.

Читайте также:  Astra linux закрытая программная среда

In this tutorial, we will show you how to use the ftp command to connect to a remote system, transfer files, and manage files and directories.

How to use the ftp command in Linux

  • Access to a local system and a remote FTP server (learn how to install an FTP server on Ubuntu, CentOS 7, or Raspberry Pi).
  • A working Internet connection.
  • Access to the terminal window.

IMPORTANT: FTP traffic is not encrypted and is thus considered unsafe. It is not recommended to transfer files over the Internet using FTP. To learn more about secure alternatives to FTP, have a look at our articles on SFTP and TSL vs. SSL.

Linux ftp Command Syntax

The Linux ftp command uses the following basic syntax:

The IP is the IP address of the system you are connecting to.

The options available for the ftp command are:

FTP Command Options Description
-4 Use only IPv4.
-6 Use only IPv6.
-e Disables command editing and history support.
-p Uses passive mode for data transfers, allowing you to use FTP despite a firewall that might prevent it.
-i Turns off interactive prompting during multiple file transfers.
-n Disables auto-login attempts on initial connection.
-g Disables file name globbing.
-v Enables verbose output.
-d Enables debugging.

The ftp command connects you to a remote system and initiates the FTP interface. The FTP interface uses the following commands to manage and transfer files to the remote system:

Command Description
! Temporarily escape to the local shell.
$ Execute a macro.
? Display help text.
account Supply a password for the remote system.
append Append a local file to a file on the remote system.
ascii Set the file transfer type to network ASCII (default type).
bell Enable a sound alert after each transfer is complete.
binary Set the file transfer type to binary image transfer.
bye Exit the FTP interface.
case Toggle upper/lower case sensitivity when ID mapping during the mget command.
cd Change the current working directory on the remote system.
cdup Change to the parent of the current working directory on the remote system.
chmod Change file permissions on the remote system.
close Exit the FTP interface.
cr Toggle carriage return stripping on ASCII file transfers.
debug Toggle debugging mode.
delete Delete a file from the remote system.
dir List the contents of a directory on the remote system.
disconnect Terminate the FTP session.
exit Terminate the FTP session and exit the FTP interface.
form Set the file transfer format.
get Transfer a file from the remote system to the local machine.
glob Toggle meta character expansion of local file names.
hash Toggle displaying the hash sign («#«) for each transferred data block.
help Display help text.
idle Set an inactivity timer for the remote system.
image Set the file transfer type to binary image transfer.
ipany Allow any type of IP address.
ipv4 Only allow IPv4 addresses.
ipv6 Only allow IPv6 addresses.
lcd Change the current working directory on the local machine.
ls List the contents of a directory on the remote system.
macdef Define a macro.
mdelete Delete multiple files on the remote system.
mdir List the contents of multiple directories on the remote system.
mget Transfer multiple files from the remote system to the local machine.
mkdir Create a directory on the remote system.
mls List the contents of multiple directories on the remote system.
mode Set the file transfer mode.
modtime Show the last time a file on the remote system was modified.
mput Transfer multiple files from the local machine to the remote system.
newer Transfer a file from the remote system to the local machine only if the modification time of the remote file is more recent than that of the local file (if a local version of the file doesn’t exist, the remote file is automatically considered newer).
nlist List the contents of a directory on the remote system.
nmap Set templates for default file name mapping.
ntrans Set translation table for default file name mapping.
open Establish a connection with an FTP server.
passive Enable passive transfer mode.
prompt Force interactive prompts when transferring multiple files.
proxy Execute command on an alternate (proxy) connection.
put Transfer a file from the local machine to the remote system.
pwd Display the current working directory on the remote system.
qc Toggle displaying a control character («?«) in the output of ASCII type commands.
quit Terminate the FTP session and exit the FTP interface.
quote Specify a command as an argument and send it to the FTP server.
recv Transfer a file from the remote system to the local machine.
reget Transfer a file from the remote system to the local machine if the local file is smaller than the remote file. The transfer starts at the end of the local file. If there is no local version of the file, the command doesn’t execute.
rename Rename a file on the remote system.
reset Clear queued command replies.
restart Restart a file transfer command at a set marker.
rhelp Display help text for the remote system.
rmdir Remove a directory on the remote system.
rstatus Show the status of the remote system.
runique Toggle storing files on the local machine with unique filenames.
send Transfer a file from the local machine to the remote system.
sendport Toggle the use of PORT commands.
site Specify a command as an argument and send it to the FTP server as a SITE command.
size Display the size of a file on the remote system.
status Show the status of the FTP interface.
struct Set the file transfer structure.
sunique Toggle storing files on the remote system with unique filenames.
system Show the operating system on the remote system.
tenex Set the file transfer type to allow connecting to TENEX machines.
tick Toggle printing byte counter during transfers.
trace Toggle packet tracing.
type Set a file transfer type.
umask Set a default permissions mask for the local machine.
user Provide username and password for the remote FTP server.
verbose Toggle verbose output.
Читайте также:  Kali linux bluetooth attacks

How to Use ftp Command in Linux

The ftp command connects a computer system to a remote server using the FTP protocol. Once connected, it also lets users transfer files between the local machine and the remote system, and manage files and directories on the remote system.

Establish an FTP Connection

To establish an FTP connection to a remote system, use the ftp command with the remote system’s IP address:

For instance, connecting to a remote server with the IP address 192.168.100.9:

Источник

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