FTP: Difference between revisions

From Alpine Linux
m (Concatenated and moved "see also" sections to bottom of article. Removed wikilink to non-existent article.)
(Large cleanup: remove all red links, correct most (if not all) errors, remove page cleanup infobox)
Line 1: Line 1:
{{Style|This page has been rampant with typos and grammar errors before,  most of which have been corrected. However, this page could probably be restructured so that the content flows more smoothly, although this is currently being worked on.}}
FTP (or '''F'''ile '''T'''ransfer '''P'''rotocol) 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 [https://en.wikipedia.org/wiki/Ftp#History_of_FTP_servers Wikipedia].
FTP (or '''F'''ile '''T'''ransfer '''P'''rotocol) 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 [https://en.wikipedia.org/wiki/Ftp#History_of_FTP_servers Wikipedia].


There are also variants of FTP. Such include SFTP (SSH FTP, not to be confused with Simple FTP), FTPS (FTP SSL), and others. SFTP, as the name implies, is done over SSH. FTPS is plain FTP with TLS/SSL encryption.
Variants of FTP also exist, including SFTP (SSH FTP, not to be confused with Simple FTP) and FTPS (FTP with SSL). SFTP, as the name implies, is done over SSH. FTPS is plain FTP with TLS/SSL encryption.


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


* {{Pkg|vsftpd}} (server)
* {{Pkg|vsftpd}} (server)
* {{Pkg|ncftp}} (client)
* {{Pkg|ncftp}} (client)
* {{Pkg|lftpd}} (client, but see below for more details).
* {{Pkg|lftpd}} (client)


There are also plenty of other clients available too, some not available in Alpine's repositories in fact. However, we will only be covering the clients and servers mentioned above. In addition, there are several graphical clients. See [[#FTP 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.


= Servers =  
= Servers =
== 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}}. 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.
 
== About vsftpd ==


vsftpd claims to be the "most secure and fastest FTP server for UNIX-like systems".  It's the default FTP server in NimbleX, Slackware, and many others. 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.


{| class="wikitable"
{| class="wikitable"
|-
|-
! Feature !! Value/Name !! Observations
! Feature                                 !! Value/Name                       !! Observations
|-
| Package name || vsftpd || <code><nowiki>apk add vsftpd</nowiki></code>
|-
|-
| Manpages and DOCs packages || vsftpd-doc || <code><nowiki>apk add vsftpd-doc</nowiki></code>
| Package name                            || vsftpd                           || <code><nowiki>apk add vsftpd</nowiki></code>
|-
|-
| Configuration file || {{Path|/etc/vsftpd/vsftpd.conf}} || Little to no customizations are made by Alpine
| Manpages and <code>-doc</code> packages || vsftpd-doc                      || <code><nowiki>apk add vsftpd-doc</nowiki></code>
|-
|-
| Default path for files || {{Path|/var/lib/ftp}} || cos anonymous are default, is home for daemon user
| Configuration file                      || {{Path|/etc/vsftpd/vsftpd.conf}} || The default config is stock from vsftpd
|-
|-
| Log files (error, access, etc) || {{Path|/var/log/vsftpd.log}} || Defined in vsftp.conf
| Default Path For Files                  || {{Path|/var/lib/ftp}}           || Because anonymous access is enabled by default, this is the daemon's default home directory
|-
|-
| User running the service || vsftpd || Others Linux used "ftp" alpine has as a group
| Log Files                              || {{Path|/var/log/vsftpd.log}}    || Configurable in vsftp.conf
|-
|-
| Group to common to || vsftpd || Used to share things among others daemons or services, like Redis or Apache
| User Running The Service                || vsftpd                           || Alpine does '''not''' have an "ftp" user; it uses a group with the same name instead.
|-
|-
| Written in || C || Main engine code in C
| Group(s) to common to                  || vsftpd                          || Used to share things among others daemons or services, like Redis or Apache
|}
|}


==== Limitations ====
==== Limitations ====


* vsftp does not support SFTP, but it does have support for FTPS.
* SFTP is not supported


=== Installing vsftpd ===
=== Installing vsftpd ===


The installation does not work out of the box, cos enable by default anonymous access is enabled and it only works with IPv4 only.
To install and run vsftpd, simply run:
 
Per user ftp files can be supported by special directive in the vsftp.conf file using <code>user_sub_token</code> to something like {{Path|/home/$USER/public_ftp}} directory by example if we enable it (process are described below in further section "vsftpd configuration".
 
{{Pkg|vsftpd}} is available in the Alpine Linux repositories. To install and run vsftpd, simply run the commands below:


<pre>
<pre>
<nowiki>
apk add vsftpd
apk add vsftpd


Line 62: Line 51:


rc-service vsftpd restart
rc-service vsftpd restart
</nowiki>
</pre>
</pre>


=== Configuring vsftpd ===
=== Configuring vsftpd ===


By default, Alpine's vsftpd package does not modify the default configuration. If you leave the configuration untouched, then vsftpd will be configured exactly the same as if you downloaded vsftpd from [[https://security.appspot.com/vsftpd.html its site]]. Regardless, you might want to change the server configuration anyways.
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 server configuration obviously depends on the your needs. 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"


For production purposes, the [[Production FTP virtual users: vsftpd + MySQL]] wiki page will explain all the requirements for setting up virtual users. The [[Production FTP user service: vsftpd]] wiki page also has further information on how to use vsftpd with system users and Let's Encrypt certificates ['''fixme''': pages doesn't exist].
=== Managing vsftpd ===


Because there are no customizations to the default configuration (in other words no Alpine-specific customizations), the configuration may not mean easy maintenance of the server, among other things. See the [[Production VSFTP system: vsftpd + MySQL + SFTP]] wiki page, which goes in depth about configuring the lighttpd web server and others ['''fixme''': page does not exist].
'''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:
 
==== Controlling 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:


{{Cmd|rc-service vsftpd start}}
{{Cmd|rc-service vsftpd start}}


After you issue this command, OpenRC will tell you the status of vsftpd.
If starting vsftpd went OK, you should see output similar to the following:


<pre>
<pre>
Line 88: Line 72:
</pre>
</pre>


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


{{Cmd|rc-service vsftpd stop}}
{{Cmd|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 issue one of the following commands below to achieve the desired effect:
'''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:


{{Cmd|rc-service vsftpd restart}}
{{Cmd|rc-service vsftpd restart}}
{{Cmd|rc-service vsftpd reload}}
{{Cmd|rc-service vsftpd reload}}


The latter command entirely restarts vsftpd, while the former only reloads vsftpd's configuration file. The former command might be more desired as it prevents having to reload vsftpd entirely.
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.


After issuing one of the commands, you might see something similar either to this output:
If you ''restarted'' vsftpd, there should be output similar to the following:
<pre>
<pre>
  * Stopping vsftpd...                                        [ ok ]
  * Stopping vsftpd...                                        [ ok ]
Line 105: Line 89:
</pre>
</pre>


(for restarting vsftpd) or to this output:
If you ''reloaded'' vsftpd, the output will be similar to the following instead:


<pre>
<pre>
Line 111: Line 95:
</pre>
</pre>


(for reloading vsftpd).
'''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:


'''Using the proper runlevel''': By default no services are added to start process. You must know what you want and what will these services do. Furthermore, runlevels aren't present in Docker containers (per se), and Alpine is used mostly in those containers. You must add the service only to the 'default' runlevel, not to the 'boot' runlevel. Networking isn't enabled during the the 'boot' runlevel, and thus it doesn't make much sense to run an FTP server without networking.
{{Cmd|rc-update add vsftpd [runlevel]}}


{{Cmd|rc-update add vsftpd default}}
Where <code>[runlevel]</code> 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 <code>rc-update add vsftpd default</code>




=== Testing vsftpd ===
=== Testing vsftpd ===


This section is assuming that vsftpd is running. At the moment, there might not be a user 'ftp' allowed 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:


{{Cmd|nc -zv server_address}}
{{Cmd|nc -zv server_address}}


Be sure to change <code>server_address</code> with the actual IP address of the server. The common response will be '''OPEN''' if the server is running.
Be sure to change <code>server_address</code> 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.


= FTP Clients =
= Clients =


As FTP uses a client-server architecture, you will need an FTP client if you want to interact with an FTP server. Alpine provides two packages for command line and batch processing of files over FTP. The following is a list of some graphical FTP 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:


* {{Pkg|pcmanfm}}. Check out [[#PCManFM with GVfs]]
* {{Pkg|firefox}}, before [https://www.mozilla.org/en-US/firefox/88.0/releasenotes/ Firefox 88], or any other web browser supporting FTP.
The following is a list of some command line FTP clients:
* {{Pkg|lftp}}. Check out [[#lftp]]
* {{Pkg|lftp}}. Check out [[#lftp]]
* {{Pkg|ncftp}}
* {{Pkg|ncftp}}


You can also use any web browser that supports FTP as an FTP client also, as is obvious. To do so, simply enter <nowiki><code>ftp://server_address</code></nowiki>, where "server_address" is the IP address of the FTP server.
If you prefer a graphical client, check out the following:
 
* {{Pkg|pcmanfm}}. See PCManFM with GVfs]]
 
Some web browsers also support FTP, although most major such as Chrome and Firefox removed support.


== lftp ==
== lftp ==


LFTP is a sophisticated file transfer program that supports a number of network protocols. Such include FTP, HTTP, SFTP, FISH, BitTorrent, and possibly more.
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:
 
lftp has the following features:


* lftp supports job control
* Job control
* The readline library is used for input
* Support for bookmarks
* lftp has support for bookmarks
* Support for a built-in mirror command
* lftp has a built-in mirror command
* Support for parallel file transfers
* lftp can transfer several files in parallel
* <code>readline</code> used for input


{| class="wikitable"
{| class="wikitable"
|-
|-
! Feature !! Value/Name !! Notes
! Feature                                 !! Value/Name !! Notes
|-
| Main package name || lftp || Install: <code><nowiki>apk add lftp</nowiki></code>
|-
| Manpages and DOCs packages || vsftpd-doc || Install: <code><nowiki>apk add lftp-doc</nowiki></code>
|-
|-
| Configuration file (system) || {{Path|/etc/lftp.conf}} || Little to no customizations are made by Alpine
| Package Name                            || lftp                                    || Install: <code><nowiki>apk add lftp</nowiki></code>
|-
|-
| Configuration file (user) || {{Path|~/.lftprc}} || The first user configuration file to read from.
| Manpages and <code>-doc</code> Packages || vsftpd-doc                              || Install: <code><nowiki>apk add lftp-doc</nowiki></code>
|-
|-
| Configuration file (user) || {{Path|~/.lftp/rc}} || Second user configuration file to read from.
| System Configuration Files              || {{Path|/etc/lftp.conf}}                 || Little to no customizations are made by Alpine
|-
|-
| Written in || C || Main engine code in C
| User Configuration Files                || {{Path|~/.lftprc}}, {{Path|~/.lftp/rc}} || The former is read first while the latter is read second if the former was not found.
|}
|}


=== Installing lftp ===
=== Installing lftp ===


To install lftp, run the following command:
To install lftp, run <pre>apk add lftp</pre>
 
<pre>
<nowiki>
apk add lftp
</nowiki>
</pre>


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 182: Line 158:
=== 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 the specified order). You can use those files to set system-wide and user-specific settings.
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.


In your configuration file, simply use the command set followed by the name of the setting, followed by its value. Use on/off for boolean values. Here's an 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:


<pre>
<pre>
<nowiki>
set ftp:ssl-force on
set ftp:ssl-force on
set ssl:verify-certificate on
set ssl:verify-certificate on
set ftp:use-feat off
set ftp:use-feat off
set ftp:ssl-protect-data on
set ftp:ssl-protect-data on
</nowiki>
</pre>
</pre>


You can set specific settings for specific servers only. Simply append a slash (/) and the server name to the setting.
Specific settings can be set for specific servers only. Append a slash (/) in front of the server name for a specific server.


<pre>
<pre>
Line 204: Line 178:
</pre>
</pre>


{{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 not currently used. See examples in the sample lftp.conf.}}
{{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 ===
=== More on lftp ===


By default, lftp is not very verbose about operations it performs in the background. If you want more output, e.g. for debugging purposes, you can use the 'debug' command (without the 'set' command):
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.
* <code>debug 5</code> will display the full debug output.
* debug 3 will only display greeting messages and error messages.
* <code>debug 3</code> will only display greeting messages and error messages.


Note that if you use the -d switch from the command line, the debug setting will be overruled and the full debug output will be displayed.
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:
If you prefer some commands to be called by another name, you can set aliases:
lftpd supports aliases in the format <code>alias [name] [command]</code>, where <code>[name]</code> is the name of the lftpd alias and <code>[command]</code> is the name of the lftpd command. A couple of examples are shown below:


<pre>
<pre>
<nowiki>
alias dir ls
alias dir ls
alias less more
alias less more
Line 225: Line 200:
alias reconnect "close; cache flush; cd ."
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.$$*"
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.$$*"
</nowiki>
</pre>
</pre>


The last alias (edit) should be all in one line. It allows you to get a remote file, edit it with vim (change as needed), and place the edited file back on the server. This is very convenient!
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 ===
=== Example usage ===


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


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


Here's a breakdown of the above command:
Breakdown:


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


== PCManFM with GVfs ==
== PCManFM with GVfs ==
Line 247: Line 222:
While PCManFM is a file manager, installing the {{Pkg|gvfs}} plugin allows you to use it as a graphical FTP client. To connect to an FTP server, you can do the following:
While PCManFM is a file manager, installing the {{Pkg|gvfs}} plugin allows you to use it as a graphical FTP client. To connect to an FTP server, you can do the following:


# From the menubar open the "go" menu
# From the menubar, go to Go > Connect to a server
# Choose "Connect to a server"
# Choose the FTP protocol and input your username (path is optional)
# Choose the FTP protocol and input your username (path is optional)
# After a while you will input the password for the username you input
# After a while you will input the password for the username you input
Check the picture for further reference.


[[File:Ftp-gui-pcmanfm_at_2020-09-11_14-13-03.png]]
[[File:Ftp-gui-pcmanfm_at_2020-09-11_14-13-03.png]]


= See Also =
= See Also =
* [[Production FTP user service: vsftpd]]
 
* [[Production FTP virtual users: vsftpd + MySQL]]
* [[PXE boot]]
* [[Production VSFTP system: vsftpd + MySQL + SFTP]]
* [[Alpine newbie]]
* [[Alpine newbie developer]]
* [[Alpine newbie developer]]
* [[Alpine newbie developer]]
* https://pkgs.alpinelinux.org/packages?name=tftp-hpa related to [[PXE boot]]


[[Category:Newbie]]
[[Category:Newbie]]

Revision as of 03:58, 9 December 2022

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 Wikipedia.

Variants of FTP also exist, including SFTP (SSH FTP, not to be confused with Simple FTP) and FTPS (FTP with SSL). SFTP, as the name implies, is done over SSH. FTPS is plain FTP with TLS/SSL 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