ThisCalculator

Everyday

SCP Not a Regular File? Error Explained

Updated · Standard formula, shown below

SCP Not a Regular File? Error Explained

If you see “SCP: not a regular file”, it means the scp command refused to copy something because the source path points to a special file type—a directory, device, socket, or pipe—rather than a normal file. The fix is to use scp -r for directories, or to copy the contents differently for other special files. Below we break down why this happens, how to work around it, and what the error really means.

What Does “Not a Regular File” Mean?

In Unix-like systems, everything is a file, but not all files are “regular”. Regular files are the ones that contain data—text, images, binaries—and can be read and written sequentially. Special files include:

  • Directories — containers for other files
  • Symbolic links — pointers to other paths (scp usually follows them, but can behave unexpectedly)
  • Device files — like /dev/null or /dev/sda
  • Named pipes (FIFOs) — used for inter-process communication
  • Sockets — endpoints for network communication

When scp encounters one of these without the proper flag, it aborts with “not a regular file” to prevent you from accidentally copying something that isn’t a normal data file.

Why scp Refuses to Copy Directories by Default

The original scp protocol (based on the older rcp) only handles regular files. A directory contains multiple files, permissions, timestamps, and subdirectories—copying it requires recursive traversal. To force that, you must add the -r (recursive) flag:

scp -r /path/to/dir user@host:/destination/

Without -r, scp sees the source is a directory, not a regular file, and stops. The same applies if the source is a symlink pointing to a directory: scp may follow the link and still complain unless you use -r.

How to Copy Special Files Correctly

Here are the common scenarios and the right approach:

  1. Directory — use scp -r (or better, rsync -a for large transfers).
  2. Symbolic link — by default, scp follows the link and copies the target. If you want the link itself, use tar or rsync -l.
  3. Device file or FIFO — scp cannot copy these meaningfully. Use tar to archive them (with --same-owner if needed) or recreate them on the target.
  4. Socket — copying a socket is almost never useful; the socket is a runtime object. Instead, copy the service configuration and restart it.

For a quick check of what a path is, use ls -l or stat. The first character of the permission string tells you: - for regular, d for directory, l for symlink, b/c for devices, p for FIFO, s for socket.

Common Causes and Solutions

You might see this error in a few typical situations:

  • You forgot -r — the most common. Add -r to the command.
  • You used a wildcard that expanded to a directory — e.g., scp * user@host:/dest/ includes subdirectories. Use scp -r * or list files explicitly.
  • The path contains a symlink to a directory — even with -r, scp might still complain if the symlink is broken. Check the link target.
  • You are trying to copy a special file like /dev/null — you probably want to copy its contents, not the device itself. Use cat /dev/null > remote or just create an empty file.

If you need to preserve permissions, timestamps, and symlinks, consider rsync over SSH:

rsync -avz /source/ user@host:/dest/

This handles directories, symlinks, and special files more gracefully than scp.

Alternatives to scp for Non-Regular Files

When scp isn’t suitable, you have several other tools:

  • rsync — the best all-around for directories and preserving metadata.
  • tar over SSH — pipe a tar archive through SSH to copy a directory tree including special files:
tar czf - /path/to/dir | ssh user@host 'tar xzf - -C /dest/'
  • SFTP — the SSH file transfer protocol, which supports recursive directory downloads/upload with get -r or put -r.
  • For device files — you generally cannot copy a device across hosts; you recreate it with mknod or by reinstalling the driver.

For most users, switching to rsync eliminates the “not a regular file” error entirely.

Frequently Asked Questions

Can I copy an empty directory with scp?

Yes, but you must use scp -r. An empty directory is still a directory, so without -r you’ll get the same error. With -r, it creates the empty directory on the remote side.

Why does scp say “not a regular file” for a symlink?

If the symlink points to a directory, scp treats it as a directory and needs -r. If the symlink is broken (target doesn’t exist), scp may also complain. Use ls -l to see the link target and decide whether to copy the link or the target.

How do I copy a file from a remote server that is a socket?

You don’t. Sockets are runtime endpoints; copying them is meaningless. Instead, copy the program that uses the socket and reconfigure it on the remote host.

What is the difference between scp and rsync for this error?

rsync is designed to handle directories and special files more robustly, and it can resume interrupted transfers, preserve permissions, and use compression. It also gives clearer error messages. For any non-trivial transfer, rsync is recommended.

Can I force scp to copy a directory without -r?

No, there is no such option. The -r flag is the only way to make scp traverse directories. You could work around it by tarring the directory and piping it, but that’s effectively using a different tool.

Does scp -r copy symbolic links as links or as targets?

By default, scp -r follows symlinks and copies the target files. If you want to preserve the symlinks themselves, you need rsync -l or a tar-based approach.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.