FTP: Difference between revisions
m (Edited firefox ftp support) |
Prabuanand (talk | contribs) (cleaned up categories, fixed wikitags, renamed headings, rephrased sentence) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
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 | 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://datatracker.ietf.org/doc/html/rfc114 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 | Alpine Linux has various [[#Clients|FTP clients]] and [[#Servers|FTP servers]] that you can install and use. | ||
== Servers == | |||
=== vsftpd === | |||
[https://security.appspot.com/vsftpd.html vsftpd] is secure, extremely fast and stable FTP server for UNIX-like systems. It's also recommended because of relatively easy configuration. | |||
Below is a list of features vsftpd has: | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Feature !! Value/Name !! | ! Feature !! Value/Name !! Notes | ||
|- | |- | ||
| | | Configuration file || {{Path|/etc/vsftpd/vsftpd.conf}} || The default config is stock from vsftpd | ||
|- | |- | ||
| | | Default Path For Files || {{Path|/var/lib/ftp}} || Because anonymous access is enabled by default, this is the daemon's default home directory | ||
|- | |- | ||
| | | Log Files || {{Path|/var/log/vsftpd.log}} || Configurable in vsftp.conf | ||
|- | |- | ||
| | | User Running The Service || vsftpd || Alpine does '''not''' have an {{ic|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 | ||
|} | |} | ||
==== | ==== Installation ==== | ||
To Install the {{Pkg|vsftpd|arch=}} package:{{Cmd|# apk add vsftpd}} Optionally install the {{Pkg|vsftpd-doc|arch=}} package alongside for documentation. | |||
==== Configuration ==== | |||
The default configuration is not ideal because anonymous access is enabled by default and only IPv4 support is enabled. Therefore, the default configuration should not be used in a production environment. 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 {{Path|/etc/vsftpd/vsftpd.conf}} file using {{ic|user_sub_token}}. For example, this can be set to something like {{Path|/home/$USER/public_ftp}}. | ||
< | The {{ic|vsftpd service}} can be enabled and the usual start|stop|restart|reload options are available as per [[OpenRC]] page: {{Cmd|<nowiki># rc-update add vsftpd default | ||
<nowiki> | # rc-service vsftpd start</nowiki>}} | ||
After changing the configuration file, you must either restart or reload vsftpd service in order for the new configuration to take effect. | |||
To test your FTP server configuration, refer to [[#Troubleshooting|Troubleshooting]] section. | |||
== | == Clients == | ||
Because FTP uses a client-server architecture, you will need an FTP client if you want to interact with an FTP server. Alpine Linux provides several packages for command-line FTP clients. A few are listed here: | |||
{| class="wikitable" | |||
|- | |||
! FTP Client | |||
|- | |||
|[[#lftp|lftp]] | |||
|- | |||
|{{Pkg|ncftp}} | |||
|- | |||
|[[#PCManFM|PCManFM]] | |||
|} | |||
lftp | === lftp === | ||
[https://lftp.yar.ru/ lftp] is a sophisticated file transfer program that supports a number of network protocols, including FTP, HTTP, SFTP, FISH, and BitTorrent. | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! Feature !! Value/Name !! Notes | ! Feature !! Value/Name !! Notes | ||
|- | |- | ||
| | | Package Name || lftp || Install: {{ic|apk add lftp}} | ||
|- | |- | ||
| Manpages and | | Manpages and <code>-doc</code> Packages || vsftpd-doc || Install: {{ic|apk add {{pkg|lftp-doc|arch=}}}} | ||
|- | |- | ||
| Configuration | | System Configuration Files || {{Path|/etc/lftp.conf}} || Little to no customizations are made by Alpine | ||
|- | |- | ||
| Configuration | | 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. | ||
|} | |} | ||
=== | ==== Installation ==== | ||
lftp | To install lftp, run {{Cmd|apk add lftp}} | ||
=== | ==== Configuration ==== | ||
The main configuration file, | 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 | 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> | ||
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 | ||
</pre> | </pre> | ||
Specific settings can be set for specific servers only. Append a slash (/) in front of the server name for a specific server. | |||
<pre> | <pre> | ||
set ftp:use-feat off /example.com | set ftp:use-feat off /example.com | ||
set ftp:ssl-force on /example.com | set ftp:ssl-force on /example.com | ||
</pre> | </pre> | ||
{{Note|The closure for | {{Note|The closure for {{ic|dns:}}, {{ic|net:}}, {{ic|ftp:}}, {{ic|http:}}, and {{ic|hftp:}} domain variables is currently just the host name as you specify it in the {{ic|open}} command (with some exceptions where closure is meaningless, e.g., {{ic|dns:cache-size}}). For some {{ic|cmd:}} domain variables the closure is the current URL without path. For other variables, it is currently not used. See examples in the sample {{ic|lftp.conf}}.}} | ||
==== lftp usage ==== | |||
Below is an example of a mult-part download over SFTP:{{Cmd|$ lftp -e 'pget -c -n 5 /path/to/file' <nowiki>sftp://username@server</nowiki>}} | |||
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 | |||
* <nowiki>sftp://username@server</nowiki>: server URL | |||
By default, lftp is | 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 | 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 using the <code>alias</code> command. The syntax is as follows: | ||
<pre> | |||
alias [name] [command] | |||
</pre> | |||
<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> | ||
alias dir ls | alias dir ls | ||
alias less more | alias less more | ||
Line 221: | Line 135: | ||
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.$$*" | ||
</pre> | </pre> | ||
The last alias | 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. | ||
=== PCManFM === | |||
[https://en.wikipedia.org/wiki/PCMan_File_Manager PCManFM] file manager available as {{pkg|pcmanfm}} package with the {{Pkg|gvfs}} plugin can be used as a graphical FTP client. To connect to an FTP server, you can do the following: | |||
# From the menubar, go to Go > Connect to a server | |||
# Choose the FTP protocol and input your username (path is optional) | |||
# After a while you will input the password for the username you input | |||
[[File:Ftp-gui-pcmanfm_at_2020-09-11_14-13-03.png]] | |||
== Troubleshooting == | |||
= | For testing, there might not be the {{ic|ftp}} user allowed or even available, but [[#vsftpd|vsftpd]] or some other ftp server server must be up and running. Use {{ic|netcat}} command from the {{pkg|netcat|arch=}} package to test if a connection to the server is successful: {{Cmd|nc -zv [server_address]}} | ||
Be sure to change {{ic|[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. | |||
== See Also == | |||
* [[PXE boot]] | |||
* [https://security.appspot.com/vsftpd.html vsftpd Homepage] | |||
* [https://lftp.yar.ru/ lftp Homepage] | |||
[[Category:Web_Server]] | [[Category:Web_Server]] | ||
Latest revision as of 17:28, 15 April 2025
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 FTP servers that you can install and use.
Servers
vsftpd
vsftpd is secure, extremely fast and stable FTP server for UNIX-like systems. It's also recommended because of relatively easy configuration.
Below is a list of features vsftpd has:
Feature | Value/Name | Notes |
---|---|---|
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 |
Installation
To Install the vsftpd package:
# apk add vsftpd
Optionally install the vsftpd-doc package alongside for documentation.
Configuration
The default configuration is not ideal because anonymous access is enabled by default and only IPv4 support is enabled. Therefore, the default configuration should not be used in a production environment. 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 /etc/vsftpd/vsftpd.conf file using user_sub_token
. For example, this can be set to something like /home/$USER/public_ftp.
The vsftpd service
can be enabled and the usual start|stop|restart|reload options are available as per OpenRC page:
# rc-update add vsftpd default # rc-service vsftpd start
After changing the configuration file, you must either restart or reload vsftpd service in order for the new configuration to take effect.
To test your FTP server configuration, refer to Troubleshooting section.
Clients
Because FTP uses a client-server architecture, you will need an FTP client if you want to interact with an FTP server. Alpine Linux provides several packages for command-line FTP clients. A few are listed here:
FTP Client |
---|
lftp |
ncftp |
PCManFM |
lftp
lftp is a sophisticated file transfer program that supports a number of network protocols, including FTP, HTTP, SFTP, FISH, and BitTorrent.
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. |
Installation
To install lftp, run
apk add lftp
Configuration
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
dns:
, net:
, ftp:
, http:
, and 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
.lftp 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
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 using the alias
command. The syntax is as follows:
alias [name] [command]
[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.
PCManFM
PCManFM file manager available as pcmanfm package with the gvfs plugin can be used as a graphical FTP client. To connect to an FTP server, you can do the following:
- From the menubar, go to Go > Connect to a server
- Choose the FTP protocol and input your username (path is optional)
- After a while you will input the password for the username you input
Troubleshooting
For testing, there might not be the ftp
user allowed or even available, but vsftpd or some other ftp server server must be up and running. Use netcat
command from the netcat package 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.