FTP: Difference between revisions

From Alpine Linux
m (Remove an obsolete FTP package. Remove secondary reference from first paragraph and replace with a primary reference.)
m (Various cleanups. pkg template overused for some packages, and not used at all for others. ic template usage. etc.)
Line 5: Line 5:
Alpine Linux has various FTP clients and servers that you can install and use, including the following:
Alpine Linux has various FTP clients and servers that you can install and use, including the following:


* {{Pkg|vsftpd}} (server)
* {{Pkg|vsftpd|arch=}} (server)
* {{Pkg|ncftp}} (client)
* {{Pkg|ncftp|arch=}} (client)


Plenty of other clients also exist, but the ones mentioned above are the only ones covered. See [[#Clients]] for more details.
Plenty of other clients also exist, but the ones mentioned above are the only ones covered. See [[#Clients]] for more details.
Line 13: Line 13:
== vsftpd ==
== vsftpd ==


In Alpine Linux the default FTP server is {{Pkg|vsftpd}}. However, it's not widely used due to common hosting panels not handling it's configuration management. In contrast, {{Pkg|vsftpd}} is more secure and doesn't require many updates.
In Alpine Linux the default FTP server is {{Pkg|vsftpd|arch=}}. However, it's not widely used due to common hosting panels not handling it's configuration management. In contrast, vsftpd is more secure and doesn't require many updates.


vsftpd also claims it's the "most secure and fastest FTP server for UNIX-like systems".  It's the default FTP server in NimbleX, Slackware, and many other Linux distributions. In addition, it's also recommended because of relatively easy configuration.
vsftpd also claims it's the "most secure and fastest FTP server for UNIX-like systems".  It's the default FTP server in NimbleX, Slackware, and many other Linux distributions. In addition, it's also recommended because of relatively easy configuration.
Line 21: Line 21:
! Feature                                !! Value/Name                      !! Observations
! Feature                                !! Value/Name                      !! Observations
|-
|-
| Package name                            || vsftpd                          || <code><nowiki>apk add vsftpd</nowiki></code>
| Package name                            || vsftpd                          || {{ic|apk add vsftpd}}
|-
|-
| Manpages and <code>-doc</code> packages || vsftpd-doc                      || <code><nowiki>apk add vsftpd-doc</nowiki></code>
| Manpages and <code>-doc</code> packages || vsftpd-doc                      || {{ic|apk add {{pkg|vsftpd-doc|arch=}}}}
|-
|-
| Configuration file                      || {{Path|/etc/vsftpd/vsftpd.conf}} || The default config is stock from vsftpd
| Configuration file                      || {{Path|/etc/vsftpd/vsftpd.conf}} || The default config is stock from vsftpd
Line 56: Line 56:
The default configuration is not ideal because anonymous access is enabled by default and IPv4 support is only enabled. Therefore, the default configuration should not be considered suitable for production uses. Some common server configuration schemes include allowing anonymous access of files, user system FTP services, and virtual users (on the server end).
The default configuration is not ideal because anonymous access is enabled by default and IPv4 support is only enabled. Therefore, the default configuration should not be considered suitable for production uses. Some common server configuration schemes include allowing anonymous access of files, user system FTP services, and virtual users (on the server end).


Per user FTP files can be supported by special directive in the vsftp.conf file using <code>user_sub_token</code>. For example, this can be set to something like {{Path|/home/$USER/public_ftp}} if we enable it (process are described below in further section "vsftpd configuration"
Per user FTP files can be supported by special directive in the vsftp.conf file using <code>user_sub_token</code>. For example, this can be set to something like {{Path|/home/$USER/public_ftp}} if we enable it (process are described below in further section "vsftpd configuration")


=== Managing vsftpd ===
=== Managing vsftpd ===


'''Starting vsftpd''': After the installation {{Pkg|vsftpd}} is not running. As we said in first section, was started already but if you want to start {{Pkg|vsftpd}} manually use:
'''Starting vsftpd''': After the installation {{Pkg|vsftpd}} is not running. As we said in first section, was started already but if you want to start vsftpd manually use:


{{Cmd|rc-service vsftpd start}}
{{Cmd|rc-service vsftpd start}}
Line 107: Line 107:
This section is assuming that vsftpd is running. At the moment, there might not be the 'ftp' user allowed or even available, but the server is up and running.
This section is assuming that vsftpd is running. At the moment, there might not be the 'ftp' user allowed or even available, but the server is up and running.


You can use netcat to test if a connection to the server is successful:
You can use {{pkg|netcat|arch=}} to test if a connection to the server is successful:


{{Cmd|nc -zv server_address}}
{{Cmd|nc -zv server_address}}
Line 122: Line 122:
If you prefer a graphical client, check out the following:
If you prefer a graphical client, check out the following:


* {{Pkg|pcmanfm}}. See PCManFM with GVfs]]
* {{Pkg|pcmanfm}}. See [[#PCManFM with GVfs]]


Some web browsers also support FTP, although most major such as Chrome and Firefox removed support.
Some web browsers also support FTP, although most major such as Chrome and Firefox removed support.
Line 140: Line 140:
! Feature                                !! Value/Name !! Notes
! Feature                                !! Value/Name !! Notes
|-
|-
| Package Name                            || lftp                                    || Install: <code><nowiki>apk add lftp</nowiki></code>
| Package Name                            || lftp                                    || Install: {{ic|apk add lftp}}
|-
|-
| Manpages and <code>-doc</code> Packages || vsftpd-doc                              || Install: <code><nowiki>apk add lftp-doc</nowiki></code>
| Manpages and <code>-doc</code> Packages || vsftpd-doc                              || Install: {{ic|apk add {{pkg|lftp-doc|arch=}}}}
|-
|-
| System Configuration Files              || {{Path|/etc/lftp.conf}}                || Little to no customizations are made by Alpine
| System Configuration Files              || {{Path|/etc/lftp.conf}}                || Little to no customizations are made by Alpine
Line 151: Line 151:
=== Installing lftp ===
=== Installing lftp ===


To install lftp, run <pre>apk add lftp</pre>
To install lftp, run {{ic|apk add lftp}}


lftp has been provided in the main repository since Alpine 3.6, so it's a supported package that's ready for production use.
lftp has been provided in the main repository since Alpine 3.6, so it's a supported package that's ready for production use.
Line 157: Line 157:
=== Configuring lftp ===
=== Configuring lftp ===


The main configuration file, <code><nowiki>/etc/lftp.conf</nowiki></code> comes with different examples and comments. On startup, lftp reads <code>/etc/lftp.conf</code>, <code>~/.lftprc</code>, and <code>~/.lftp/rc</code> in that exact order. These files are used to set system-wide and user-specific settings.
The main configuration file, {{path|/etc/lftp.conf}} comes with different examples and comments. On startup, lftp reads {{path|/etc/lftp.conf}}, {{path|~/.lftprc}}, and {{path|~/.lftp/rc}} in that exact order. These files are used to set system-wide and user-specific settings.


In the configuration file, use the command set followed by the name of the setting followed by its value. Use <code>on</code>/<code>off</code> for boolean values. For example:
In the configuration file, use the command set followed by the name of the setting followed by its value. Use <code>on</code>/<code>off</code> for boolean values. For example:

Revision as of 04:54, 12 January 2024

FTP (or File Transfer Protocol) is a protocol that allows you to transfer files from a server to a client and vice versa (as FTP uses a client-server architecture). FTP is among the oldest protocols as its origins can be traced as far back as 1971 according to RFC 114.

Variants of FTP also exist, including SFTP (SSH FTP, not to be confused with Simple FTP) and FTPS (FTP with TLS). SFTP, as the name implies, is done over SSH. FTPS is plain FTP with TLS encryption.

Alpine Linux has various FTP clients and servers that you can install and use, including the following:

Plenty of other clients also exist, but the ones mentioned above are the only ones covered. See #Clients for more details.

Servers

vsftpd

In Alpine Linux the default FTP server is vsftpd. However, it's not widely used due to common hosting panels not handling it's configuration management. In contrast, vsftpd is more secure and doesn't require many updates.

vsftpd also claims it's the "most secure and fastest FTP server for UNIX-like systems". It's the default FTP server in NimbleX, Slackware, and many other Linux distributions. In addition, it's also recommended because of relatively easy configuration.

Feature Value/Name Observations
Package name vsftpd apk add vsftpd
Manpages and -doc packages vsftpd-doc apk add vsftpd-doc
Configuration file /etc/vsftpd/vsftpd.conf The default config is stock from vsftpd
Default Path For Files /var/lib/ftp Because anonymous access is enabled by default, this is the daemon's default home directory
Log Files /var/log/vsftpd.log Configurable in vsftp.conf
User Running The Service vsftpd Alpine does not have an "ftp" user; it uses a group with the same name instead.
Group(s) to common to vsftpd Used to share things among others daemons or services, like Redis or Apache

Limitations

  • SFTP is not supported

Installing vsftpd

To install and run vsftpd, simply run:

apk add vsftpd

rc-update add vsftpd default

rc-service vsftpd restart

Configuring vsftpd

The default configuration is not ideal because anonymous access is enabled by default and IPv4 support is only enabled. Therefore, the default configuration should not be considered suitable for production uses. Some common server configuration schemes include allowing anonymous access of files, user system FTP services, and virtual users (on the server end).

Per user FTP files can be supported by special directive in the vsftp.conf file using user_sub_token. For example, this can be set to something like /home/$USER/public_ftp if we enable it (process are described below in further section "vsftpd configuration")

Managing vsftpd

Starting vsftpd: After the installation vsftpd is not running. As we said in first section, was started already but if you want to start vsftpd manually use:

rc-service vsftpd start

If starting vsftpd went OK, you should see output similar to the following:

 * Caching service dependencies ...                           [ ok ]
 * Starting vsftpd...                                         [ ok ]

Stopping vsftpd: if you want to stop the web server use stop in the same way of previous command:

rc-service vsftpd stop

Restarting or reloading vsftpd: After changing the configuration file, you must either restart or reload vsftpd in order for the new configuration to take effect. You can run one of the following commands below to achieve the desired effect:

rc-service vsftpd restart

rc-service vsftpd reload

The latter reloads vsftpd's configuration file while the former restarts vsftpd entirely. The latter might be preferred as it prevents having to reload vsftpd entirely.

If you restarted vsftpd, there should be output similar to the following:

 * Stopping vsftpd...                                         [ ok ]
 * Starting vsftpd...                                         [ ok ]

If you reloaded vsftpd, the output will be similar to the following instead:

 * Reloading vsftpd...                                        [ ok ]

Using the proper runlevel: using the "default" runlevel should work in most cases, although there might be custom runlevels present and it might be more desirable to add vsftpd to a runlevel other than "default". However, keep in mind that runlevels aren't present in Docker containers because Alpine is used mostly in Docker.

To add vsftpd to a runlevel, use the following command:

rc-update add vsftpd [runlevel]

Where [runlevel] is the name of the runlevel you want to add the vsftpd service too. For example, if you want to add vsftpd to the "default" run level, run rc-update add vsftpd default


Testing vsftpd

This section is assuming that vsftpd is running. At the moment, there might not be the 'ftp' user allowed or even available, but the server is up and running.

You can use netcat to test if a connection to the server is successful:

nc -zv server_address

Be sure to change server_address with the actual IP address of the server. The common response will be OPEN if the server is running. If you receive another response, review your server configuration.

Clients

Because FTP uses a client-server architecture, you will need an FTP client if you want to interact with an FTP server. Alpine provides several packages for command-line FTP clients:

If you prefer a graphical client, check out the following:

Some web browsers also support FTP, although most major such as Chrome and Firefox removed support.

lftp

lftp is a sophisticated file transfer program that supports a number of network protocols, including FTP, HTTP, SFTP, FISH, and BitTorrent. It also has the following features:

  • Job control
  • Support for bookmarks
  • Support for a built-in mirror command
  • Support for parallel file transfers
  • readline used for input
Feature Value/Name Notes
Package Name lftp Install: apk add lftp
Manpages and -doc Packages vsftpd-doc Install: apk add lftp-doc
System Configuration Files /etc/lftp.conf Little to no customizations are made by Alpine
User Configuration Files ~/.lftprc, ~/.lftp/rc The former is read first while the latter is read second if the former was not found.

Installing lftp

To install lftp, run apk add lftp

lftp has been provided in the main repository since Alpine 3.6, so it's a supported package that's ready for production use.

Configuring lftp

The main configuration file, /etc/lftp.conf comes with different examples and comments. On startup, lftp reads /etc/lftp.conf, ~/.lftprc, and ~/.lftp/rc in that exact order. These files are used to set system-wide and user-specific settings.

In the configuration file, use the command set followed by the name of the setting followed by its value. Use on/off for boolean values. For example:

set ftp:ssl-force on
set ssl:verify-certificate on
set ftp:use-feat off
set ftp:ssl-protect-data on

Specific settings can be set for specific servers only. Append a slash (/) in front of the server name for a specific server.


set ftp:use-feat off /example.com
set ftp:ssl-force on /example.com

Note: The closure for `dns:', `net:', `ftp:', `http:', `hftp:' domain variables is currently just the host name as you specify it in the `open' command (with some exceptions where closure is meaningless, e.g., dns:cache-size). For some `cmd:' domain variables the closure is the current URL without path. For other variables, it is currently not used. See examples in the sample lftp.conf.

More on lftp

By default, lftp is not very verbose about operations it performs in the background. If you want more output, you can use the 'debug' command (without the 'set' command):

  • debug 5 will display the full debug output.
  • debug 3 will only display greeting messages and error messages.

Note that using the -d switch from the command line will override any previous debug settings and the full debug output will be displayed.

If you prefer some commands to be called by another name, you can set aliases:

lftpd supports aliases in the format alias [name] [command], where [name] is the name of the lftpd alias and [command] is the name of the lftpd command. A couple of examples are shown below:

alias dir ls
alias less more
alias zless zmore
alias bzless bzmore
alias reconnect "close; cache flush; cd ."
alias edit "eval -f "get $0 -o ~/.lftp/edit.tmp.$$ && shell \\"cp -p ~/.lftp/edit.tmp.$$ ~/.lftp/edit.tmp.$$.orig && vim ~/.lftp/edit.tmp.$$ && test ~/.lftp/edit.tmp.$$ -nt ~/.lftp/edit.tmp.$$.orig\\" && put ~/.lftp/edit.tmp.$$ -o $0; shell rm -f ~/.lftp/edit.tmp.$$*"

The last alias should all be in one line. It gets a remote file, opens it with vim, and places the modified file back on the server. This can be very convenient when a file needs to be quickly edited and updated on the remote server.

Example usage

Below is an example of a mult-part download over SFTP:

$ lftp -e 'pget -c -n 5 /path/to/file' sftp://username@server

Breakdown:

  • -e: execute a command
  • pget: the command for partial download, in addition to its options:
    • -c: option to resume
    • -n: option for number of parts
  • sftp://username@server: server URL

PCManFM with GVfs

While PCManFM is a file manager, installing the gvfs plugin allows you to use it as a graphical FTP client. To connect to an FTP server, you can do the following:

  1. From the menubar, go to Go > Connect to a server
  2. Choose the FTP protocol and input your username (path is optional)
  3. After a while you will input the password for the username you input

See Also