sftp put -r: copy a whole folder, and "Couldn't canonicalize"
Upload or download a whole folder with sftp put -r or get -r, why put -r fails with Couldn't canonicalize or path canonicalization failed, and scp -r.
The OpenSSH sftp command copies one file per put or get unless you ask for a recursive copy.
The commands
put -r site
get -r logs
put -r site uploads the local folder site, with everything in it, into the current remote folder as site. get -r logs does the same in the other direction. -R means the same as -r. Starting the program as sftp -r [email protected] makes every put and get in that session recursive.
A recursive copy does not follow symbolic links it finds in the tree. Add -p to keep permissions and times.
"is not a regular file"
You named a folder without -r. Current OpenSSH prints local "site/" is not a regular file on upload, and a line such as download /home/user1/logs/: not a regular file on download. Repeat the command with -r.
"Couldn't canonicalize" or "path canonicalization failed"
Before a recursive upload, the client asks the server for the full path of the destination folder. Some servers cannot answer for a path that does not exist yet, and the copy stops before any file is sent:
Couldn't canonicalize: No such file or directory
upload "/home/user1/site": path canonicalization failed
The first form comes from older sftp clients, the second from current ones. Current OpenSSH servers accept a destination whose last folder is missing and the client then creates it, but every folder above it must already exist. Older servers and some other SFTP servers need the destination itself to exist.
Fix: create the destination first, then copy.
mkdir site
put -r site
For a deeper path, recent sftp clients accept mkdir -p /srv/www/site, which creates the missing parent folders and does not complain if they exist. With an older client, run mkdir once per level.
Copy the contents, not the folder
To put the files of site into a remote folder that already exists, use a wildcard:
put -r site/* /srv/www/html
Resume a broken transfer
put -a and get -a (or reput and reget) continue a partial copy of a file. They assume the partial copy matches the original. If it does not, the result is likely to be corrupt.
scp -r instead
scp -r site [email protected]:/srv/www/ copies a folder in one command. Current scp uses the SFTP protocol underneath. Unlike sftp, scp -r follows symbolic links it finds in the tree.
Related
- SFTP
- SFTP "Received message too long"
- SFTP file browser errors: Permission denied, No such file
- SSH: how it works