FTP and SFTP settings and errors
FTP, FTPS, and SFTP: differences and ports
-
ftp://ftp.example.com:21Plain FTP: the user name, password, and files travel unencrypted, so anyone along the way can read them. Fine for an internal network or for testing, not for transferring files over the internet.
-
AUTH TLSExplicit FTPS (encryption the client requests after the connection opens, on port 21): the connection opens like plain FTP, and the client sends the AUTH TLS command to encrypt it before it sends the user name and password. This is the standard way to encrypt FTP. In FileZilla, choose Require explicit FTP over TLS in the Encryption field.
Example:
234 AUTH TLS successful -
PBSZ 0 / PROT PCommands the client sends after AUTH TLS to encrypt the data connections too, which carry the files and directory listings. Without PROT P, the data connection stays unencrypted, even when the login itself is encrypted.
-
ftps://ftp.example.com:990Implicit FTPS (encrypted from the first moment, on a separate port): the connection is encrypted right from the start, usually on port 990. It's an older method that isn't part of the FTPS standard, and most servers and clients prefer Explicit FTPS on port 21.
-
sftp://user@203.0.113.10:22SFTP isn't FTP but a separate protocol that runs inside an SSH connection, on port 22. All traffic is encrypted, everything goes through a single connection with no extra port range, and you log in with your SSH user and password or key. When you have SSH access to the server, this is the recommended choice.
-
scp -P 2222 index.php user@203.0.113.10:/var/www/site/scp copies files over SSH in a single command, with no interactive mode. The port is set with a capital P, as in sftp. In recent OpenSSH versions, scp uses the SFTP protocol behind the scenes.
Active mode and Passive mode
-
PORT 192,168,1,20,195,80Active mode: the client tells the server an address and port on its own computer, and the server opens the data connection from its side to that computer. A home router or a firewall on the computer usually blocks such an incoming connection, so Active mode fails on most networks.
-
PASVPassive mode: the client asks the server to open a port, and the server replies with the address and port to connect to. The first four numbers are the IP address, and the port is calculated from the last two: 195 times 256 plus 80, which is 50000. This is the default mode in FileZilla and curl, because all connections go out from the user's computer.
Example:
227 Entering Passive Mode (203,0,113,10,195,80) -
EPSVAn extended version of Passive mode: the server returns only the port number, without an IP address. That way it also works over IPv6 and isn't affected by a wrong internal address in the server's reply. curl tries EPSV first, and only then PASV.
Example:
229 Entering Extended Passive Mode (|||50000|) -
curl --ftp-port - -u user ftp://ftp.example.com/Switches curl to Active mode: the server connects back to your computer, and the hyphen means using the same address as the control connection. Use it only when the server doesn't allow Passive mode.
Port range and firewall
-
sudo ufw allow 21/tcpOpens port 21 in UFW, for FTP and Explicit FTPS connections.
-
sudo ufw allow 40000:50000/tcpOpens the Passive mode port range. For a port range, you must specify the tcp protocol. The range must match the one set on the FTP server, or the file listing won't load.
-
sudo firewall-cmd --permanent --add-service=ftpOpens the FTP service in firewalld, that is, port 21.
-
sudo firewall-cmd --permanent --add-port=40000-50000/tcpOpens the Passive mode port range in firewalld. firewalld separates the ends of the range with a hyphen, and UFW with a colon. With an FTPS connection, the firewall can't read the encrypted commands to detect the data ports, so you open the range explicitly.
-
sudo firewall-cmd --reloadLoads the permanent rules, so the changes added with --permanent take effect.
-
sudo ss -tlnp | grep -E ':(21|22|990) 'Shows which services listen on the server on ports 21, 22, and 990. When a port isn't listed, the service isn't running or listens on another port, and opening it in the firewall won't help.
Transferring files with sftp
-
sftp user@203.0.113.10Opens an interactive SFTP session to the server, with the same SSH user and password or key.
Example:
sftp> -
sftp -P 2222 user@203.0.113.10Connects to a server whose SSH service listens on a port other than 22. In sftp, the port is set with a capital P, unlike ssh.
-
sftp -i ~/.ssh/id_ed25519 user@203.0.113.10Connects with a specific private key.
-
ls -lInside sftp: lists the files in the current directory on the server, with permissions, size, and date. The lls command lists the files in the directory on your computer.
-
cd /var/www/siteChanges to a directory on the server. The lcd command changes the directory on your computer, and pwd and lpwd show the current directory on each side.
-
get backup.zipDownloads a file from the server to the current directory on your computer. With -r, as in get -r uploads, it downloads a whole directory with all its contents.
-
put index.phpUploads a file from your computer to the current directory on the server, and replaces an existing file with the same name. With -r, as in put -r site, it uploads a whole directory.
-
reget backup.zipResumes an interrupted download instead of starting over. The reput command resumes an interrupted upload. Both are especially useful for large files.
-
mkdir backupsCreates a directory on the server. The rmdir command deletes an empty directory.
-
rm old-backup.zipCaution: deletes a file on the server without asking for confirmation, and it can't be undone.
-
chmod 644 index.phpChanges the permissions of a file on the server. The chown command accepts only a numeric user ID, not a name.
-
sftp user@203.0.113.10:/var/www/site/backup.zipDownloads a single file in one command, with no interactive mode.
-
sftp -b upload.txt user@203.0.113.10Runs the commands in the upload.txt file, one command per line. The run stops at the first command that fails, and a hyphen before a command, as in -rm, continues even when it fails. Built for scripts, so use it with an SSH key rather than a password.
FTPS on the command line: lftp and curl
-
lftp -u user -e 'set ftp:ssl-force true' ftp.example.comConnects with lftp and requires encryption: when the server doesn't support TLS, lftp won't send the password unencrypted. Avoid typing the password on the command line, because it's saved in the shell history.
-
mirror -R --only-newer --parallel=4 ./site /public_htmlInside lftp: uploads the local site directory to the server (-R), only files newer than those on the server, four files in parallel.
-
mirror -R --delete --dry-run ./site /public_htmlCaution: --delete removes files on the server that don't exist on your computer. --dry-run shows what would be done without changing anything, and only after checking it do you run the command without --dry-run.
-
lftp sftp://user@203.0.113.10lftp can also connect over SFTP, with the same commands, including mirror.
-
curl --ssl-reqd -u user ftp://ftp.example.com/public_html/Lists the files in a directory over an Explicit FTPS connection. --ssl-reqd stops the connection when the server doesn't support encryption, instead of continuing without it. When you specify only a user name, curl prompts for the password.
-
curl --ssl-reqd -u user -T index.html ftp://ftp.example.com/public_html/Uploads a file to the server. The trailing slash in the URL marks a directory, and curl saves the file under its original name.
-
curl --ssl-reqd -u user --ftp-create-dirs -T report.pdf ftp://ftp.example.com/public_html/files/2026/Creates the missing directories in the path on the server before the upload. Without this option, the upload fails when the directory doesn't exist.
-
curl --ssl-reqd -u user -o backup.zip ftp://ftp.example.com/backup.zipDownloads a file from the server and saves it as backup.zip.
-
curl -u user ftps://ftp.example.com/An Implicit FTPS connection: the ftps:// URL opens a connection that's encrypted from the start, on port 990 by default. For Explicit FTPS, use ftp:// with --ssl-reqd.
SFTP-only users locked to a directory (OpenSSH)
-
sudo groupadd sftponlyCreates a group for users who get SFTP only, with no shell. The restriction applies to every member of the group.
-
sudo useradd -g sftponly -s /usr/sbin/nologin webdev && sudo passwd webdevCreates a user in the group, without shell login, and sets a password for it.
-
sudo mkdir -p /srv/sftp/webdev/uploadsCreates the directory that will be the user's root, with a subdirectory inside it where the user can write.
-
sudo chown root:root /srv/sftp/webdev && sudo chmod 755 /srv/sftp/webdevRequired: every directory in the ChrootDirectory path must be owned by root and not writable by the group or others. That's why the user can't write in the root directory itself.
-
sudo chown webdev:sftponly /srv/sftp/webdev/uploadsGives the user ownership of the subdirectory, where they upload and create files.
-
Subsystem sftp internal-sftpIn /etc/ssh/sshd_config: the built-in OpenSSH SFTP server, which needs no extra files inside the chroot directory. Replace the existing Subsystem line instead of adding a second one.
-
Match Group sftponlyAt the end of the file: the settings after this line apply only to members of the sftponly group, up to the next Match line or the end of the file. That's why the block goes at the end.
-
ChrootDirectory /srv/sftp/%uLocks the user in their directory, so they can't see the rest of the server. %u is replaced with the user name, and %h with the user's home directory.
-
ForceCommand internal-sftpAllows the user SFTP only: even when they try to open a shell or run a command, the built-in SFTP server starts.
-
AllowTcpForwarding noPrevents the user from opening tunnels through the server. Set X11Forwarding no along with it.
-
sudo sshd -t && sudo systemctl reload sshdChecks the file for errors, and only when there are none reloads the service. On Ubuntu and Debian, the service is named ssh. Keep a session open until a new login succeeds.
-
fatal: bad ownership or modes for chroot directoryThe message in the SSH service log when a directory in the ChrootDirectory path isn't owned by root or is writable by others. The user sees only an immediate disconnect. Fix it with chown root:root and chmod 755 on every directory in the path.
vsftpd server: main settings
-
anonymous_enable=NOIn vsftpd.conf, located at /etc/vsftpd.conf on Ubuntu and Debian and at /etc/vsftpd/vsftpd.conf on AlmaLinux and Rocky Linux: disables anonymous login, which is on by default in vsftpd's settings.
-
local_enable=YESAllows system users to log in. Required for any login that isn't anonymous.
-
write_enable=YESAllows commands that change files: uploading, deleting, renaming, and creating directories. Without it, the account is read-only.
-
local_umask=022Sets the permissions of new files: 644 for files and 755 for directories, the usual permissions for a website. The vsftpd default is 077, which lets only the owner read.
-
chroot_local_user=YESLocks each user in their home directory after login, so they can't browse the rest of the server.
-
500 OOPS: vsftpd: refusing to run with writable root inside chroot()This error appears when a locked user's home directory is writable by that user. The recommended fix: a home directory owned by root with no write permission, and a subdirectory inside it where the user writes.
-
allow_writeable_chroot=YESCaution: allows locking a user in a home directory they can write to, and suppresses the previous error. This bypasses a security check, so it's better to fix the directory's ownership.
-
pasv_min_port=40000The start of the Passive mode port range. Together with pasv_max_port=50000, the range is limited, so you can open it in the firewall. Without these settings, the server picks any free port.
-
pasv_address=203.0.113.10The address the server returns in its PASV reply. Set it when the server is behind NAT, so it returns the public address and not an internal one.
-
ssl_enable=YESEnables Explicit FTPS. When it's on, regular users must by default encrypt both the password and the data. Set the certificate and key with rsa_cert_file and rsa_private_key_file.
-
sudo systemctl restart vsftpdRestarts vsftpd, so the changes in the configuration file take effect.
Common errors in FileZilla and other FTP clients
-
Error: Connection timed out after 20 seconds of inactivityFileZilla got no reply from the server for 20 seconds. When it happens while connecting, a firewall blocks the port or the address is wrong. When it happens right after connecting, while the file listing loads, the Passive mode port range is blocked on the server or on a router in front of it.
-
Error: Failed to retrieve directory listingThe login succeeded, but the data connection for the file listing failed. In most cases, the Passive range isn't open in the server's firewall, or the server returns an internal address in its PASV reply. Open the range and set the public address on the server. To test, you can change the transfer mode in Site Manager, on the Transfer Settings tab.
-
ECONNREFUSED - Connection refused by serverThe server is reachable, but no service listens on the chosen port, or a firewall rejects the connection. Check the port: 21 for FTP and Explicit FTPS, 22 for SFTP. A common mistake is an SFTP connection to port 21 or an FTP connection to port 22.
-
Error: Critical error: Could not connect to serverA summary message that appears after all connection attempts have failed. The actual cause appears in the lines above it, so read the log from the top.
-
530 Login authentication failedCode 530 means the login was rejected. Check the full user name, which for FTP accounts on web hosting sometimes includes the domain too, such as user@example.com. If you copied the password, check that no space was added at the end. After many failed attempts, the server's firewall may block your address temporarily.
-
550 Permission deniedThe account has no permission to read or write the file or directory. Files uploaded as root or as another user can't be changed with the FTP account, so check ownership and permissions. Code 550 also appears when the file doesn't exist or the path is wrong.
-
553 Could not create file.The server refused to create the file: there's no write permission in the directory, the file name isn't allowed, or the account's disk space is full.
-
425 Can't open data connectionThe server couldn't open the data connection. In Passive mode, check the range in the server's firewall, and in Active mode, the firewall on your computer and router.
-
Status: Server sent passive reply with unroutable address. Using server address instead.The server returned an internal address in its PASV reply, such as 192.168.x.x or 10.x.x.x, and FileZilla uses the server's address instead. This is a status message, not an error, but it shows that the server is behind NAT and doesn't know its public address. Set it on the server, for example with pasv_address in vsftpd.
-
GnuTLS error -15 in gnutls_record_recv: An unexpected TLS packet was received.The encrypted connection received data from the server that doesn't match TLS. In most cases, the server hit an error after login and closed the connection, for example vsftpd with a locked home directory the user can write to, so check the FTP server log first. Another cause is a firewall, router, or antivirus that interferes with the encrypted traffic.
-
GnuTLS error -110 in gnutls_record_recv: The TLS connection was non-properly terminated.The encrypted connection closed without a proper TLS shutdown, usually because of a disconnect on the server side, a timeout, or a firewall along the way. When the message comes back on every transfer, check the server's time limits and Passive range.
-
Unknown certificateA window that appears when you connect over FTPS and the server's certificate isn't recognized, such as a self-signed certificate, or when the name in the certificate differs from the address you entered. Before you accept, check that the details in the window, especially the fingerprint, match your server. Connecting to the server name shown in the certificate prevents the message.
-
Disconnected: No supported authentication methods available (server sent: publickey)The SSH server allows key login only, and FileZilla didn't send a key. In Site Manager, set the Logon Type field to Key file and attach the private key. The public key must be in the user's authorized_keys file on the server.
-
Received unexpected end-of-file from SFTP serverThe SSH connection succeeded, but the SFTP service didn't start. Common causes: a wrong Subsystem line in the server settings, a chroot directory not owned by root, or a startup file such as .bashrc that prints text at login. The exact cause appears in the SSH service log on the server.
-
421 Too many connectionsThe server limits the number of connections from a single address. Lower the number of simultaneous transfers in FileZilla's settings, under Transfers, or limit the number of connections to the server in Site Manager.
File permissions for websites
-
find /var/www/site -type d -exec chmod 755 {} +Sets 755 permissions on all the site's directories: the owner writes, and everyone else reads and enters the directory.
-
find /var/www/site -type f -exec chmod 644 {} +Sets 644 permissions on all the site's files: the owner reads and writes, and everyone else reads only. Configuration files with passwords call for stricter permissions, such as 640 or 600, as long as the site can still read them.
-
sudo chown -R webdev:webdev /var/www/siteTransfers ownership of the site files to the user who uploads them. This fixes a 550 error on files previously uploaded as root or as another user.
-
chmod 777Caution: a permission that lets any user on the server write to the file or directory. It doesn't fix an ownership problem, and it opens the door to unauthorized changes to files. Fix the ownership instead.
No matching commands, settings, and errors.
Names and addresses in the examples
The examples on this page use the example.com domain and IP addresses reserved for documentation, such as 203.0.113.10, so replace them with your server's name and address. The 40000 to 50000 port range is also an example: you can choose another range, as long as it's the same on the FTP server and in the firewall.
Which protocol to choose
- SFTP: when you have SSH access to the server. One encrypted connection, no extra port range, and you can log in with a key instead of a password.
- Explicit FTPS: when the service provides FTP accounts. The same account and the same port 21, with the password and the files encrypted.
- Unencrypted FTP: only on an internal network. Over the internet, the password travels as plain text.
Checking a failed connection, in order
- Port and connection type: 21 for FTP and Explicit FTPS, 990 for Implicit FTPS, 22 for SFTP. Most login errors start with the wrong choice here.
- Login details: the full user name, and a password with no spaces. With SFTP, check the key too. The common causes are on the Common SSH errors page.
- A file listing that won't load: almost always Passive mode. Open the range in the firewall, for example with UFW or firewalld, and on a server behind NAT set the public address.
- Permission errors: check ownership and permissions. You'll find a full explanation on the Linux file permissions page, and you can work out the numeric value with the chmod calculator.
Syncing a whole site
For uploading individual files, FileZilla or sftp work well. For syncing a whole site or for repeat backups, when you have SSH access, rsync is the better choice, because it transfers only what changed.
With Linux hosting plans, you manage your site files in the file manager of the control panel or with unlimited FTP accounts. A Linux VPS comes with full root access over SSH, so you can transfer files over SFTP, create a separate SFTP user for each developer, and install an FTP server as needed.
FTP and SFTP FAQ
What's the difference between FTP, FTPS, and SFTP?
FTP is the long-standing file transfer protocol, and with it the password and files travel unencrypted. FTPS is the same FTP with TLS encryption, usually on the same port 21. SFTP is a different protocol that runs inside an SSH connection on port 22, encrypts all traffic, and uses a single connection. When you have SSH access to the server, SFTP is the most convenient and secure choice. When you have only an FTP account, choose Explicit FTPS, that is, encrypted FTPS on port 21.
Why does FileZilla connect but the file listing doesn't load?
With FTP, the login goes through port 21, while the file listing and the files themselves go through a separate connection, to a port from a range the server sets in Passive mode. When that range isn't open in the server's firewall, or the server returns an internal address, the login succeeds and the file listing hangs. Open the range, and on a server behind NAT set the public address. SFTP doesn't have this problem, because everything goes through a single connection.
What's a convenient program for uploading files to a website?
FileZilla runs on Windows, macOS, and Linux and supports FTP, FTPS, and SFTP. WinSCP is also popular on Windows, and Cyberduck on macOS. In every program, you enter the server address, the user name, the password or key, and the port, and you save the connection in Site Manager so you can connect with one click. If you work on the command line, you can use sftp, lftp, or curl.
How do I give an outside developer access to the site's directory only?
On a server with OpenSSH, create a user for the developer in a dedicated group, and set ChrootDirectory and ForceCommand internal-sftp for that group in sshd_config. The developer connects over SFTP, sees only the directory assigned to them, and can't open a shell or reach the rest of the server. When the work is done, just lock or delete the user.
What permissions should a website's files and directories have?
For most websites, 644 for files and 755 for directories work well: the owner reads and writes, and everyone else reads only. Configuration files with passwords call for stricter permissions, such as 640 or 600. When an upload fails because of permissions, the fix is to correct the file ownership, not to set 777 permissions.