# FTP Im Terminal verwenden

<p class="callout info">Zum Austausch von Dateien zwischen FTP Server und Linux Rechner im Terminal </p>

<p class="callout info">[FTP Server auf Linux installieren ](https://books.hhml.selfhost.co/books/linux/page/ftp-server-installieren-fur-paperless "FTP-Server Installieren für Paperless")</p>

In this tutorial, I will explain how to use the Linux ftp command on the shell. I will show you how to connect to an FTP server, up- and download files and create directories. While there are many nice desktops FTP clients available, the FTP command is still useful when you work remotely on a server over an SSH session and e.g. want to fetch a backup file from your FTP storage.<span class="ezoic-adpicker-ad" id="bkmrk--7"></span>

## FTP

### Step 1: Establishing an FTP connection

To connect to the FTP server, we have to type in the terminal window 'ftp' and then the domain name 'domain.com' or IP address of the FTP server.<span class="ezoic-adpicker-ad" id="bkmrk--8"></span>

<div class="page-content" id="bkmrk-"><div class="page-content"><div dir="auto"><div id="bkmrk--1">  
</div></div></div></div>**Examples:**

```
ftp domain.com
```

```
ftp 192.168.0.1
```

```
ftp user@ftpdomain.com
```

Note: for this example we used an anonymous server.

Replace the IP and domain in the above examples with the IP address or domain of your FTP server.[](https://www.howtoforge.com/images/how-to-use-ftp-in-the-linux-shell/big/ftpanonymous.png)  
<span class="ezoic-adpicker-ad" id="bkmrk--10"></span>

### Step 2: Login with User and Password

Most FTP servers logins are password protected, so the server will ask us for a 'username' and a 'password'.

If you connect to a so-called anonymous FTP server, then try to use "anonymous" as username and an empty password:

```
Name: anonymous
```

```
Password:
```

The terminal will return a message like this:

```
230 Login successful.<br></br>Remote system type is UNIX.<br></br>Using binary mode to transfer files.<br></br>ftp>
```

When you are logged in successfully. <span class="ezoic-adpicker-ad" id="bkmrk--11"></span>

  
[![Successful FTP login.](https://www.howtoforge.com/images/how-to-use-ftp-in-the-linux-shell/login.png?ezimgfmt=rs:249x322/rscb5/ng:webp/ngcb5)](https://www.howtoforge.com/images/how-to-use-ftp-in-the-linux-shell/big/login.png)

### Step 3: Working with Directories

The commands to list, move and create folders on an FTP server are almost the same as we would use the shell locally on our computer, ls stands for list, cd to change directories, mkdir to create directories...

#### Listing directories with security settings:

```
ftp> ls
```

The server will return:

[](https://www.howtoforge.com/images/how-to-use-ftp-in-the-linux-shell/big/listing.png)

#### Changing Directories:

To change the directory we can type:<span class="ezoic-adpicker-ad" id="bkmrk--14"></span>

```
ftp> cd directory
```

The server will return:

### Step 4: Downloading files with FTP

<p class="callout info">Before downloading a file, we should set the local FTP file download directory by using 'lcd' command:</p>

```
lcd /home/user/yourdirectoryname
```

If you dont specify the download directory, the file will be downloaded to the current directory where you were at the time you started the FTP session.

Now, we can use the command 'get' command to download a file, the usage is:<span class="ezoic-adpicker-ad" id="bkmrk--16"></span>

```
get file
```

  
The file will be downloaded to the directory previously set with the 'lcd' command.

The server will return the next message:

[](https://www.howtoforge.com/images/how-to-use-ftp-in-the-linux-shell/big/gettingfile.png)

To download several files we can use wildcards. In this example, I will download all files with the .xls file extension.

```
mget *.xls
```

<span class="ezoic-adpicker-ad" id="bkmrk--18"></span>

### Step 5: Uploading Files with FTP

  
We can upload files that are in the local directory where we made the FTP connection.  
  
To upload a file, we can use 'put' command.

```
put file
```

When the file that you want to upload is not in the local directory, you can use the absolute path starting with "/" as well:

```
put /path/file
```

To upload several files we can use the mput command similar to the mget example from above:

```
mput *.xls
```

### Step 6: Closing the FTP connection

Once we have done the FTP work, we should close the connection for security reasons. There are three commands that we can use to close the connection:

```
bye
```

```
exit
```

```
quit
```

 Any of them will disconnect our PC from the FTP server and will return:

```
221 Goodbye
```

## SFTP

Sicheres Übertragen

### Verbindung herstellen

```
sftp user@10.1.1.10
```

#### Ordner übertragen 

```
# Hochladen

put -r Ordnername

# herunterladen

get -r Ordnername 
```