SCP File Transfer Not Overwriting Destination: Debugging Permission and Cache Issues


2 views

When executing:

scp /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

The progress bar shows normal transfer activity, yet the destination file's timestamp and checksum remain unchanged. Manual deletion of the target file appears to be the only workaround.

1. Permission Inheritance
The destination directory might have restrictive permissions preventing in-place modification. Try:

ssh hostname ls -la /home/user/

Look for write permissions (w flag) for your user on both the directory and file.

2. SSHFS/CIFS Mount Point Cache
Network-mounted filesystems often have aggressive caching. Force metadata refresh with:

ssh hostname sync

Verify actual file transfer with verbose mode:

scp -v /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

Check for "Sink:" status messages indicating successful write operations.

Method 1: Atomic Replacement

scp /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz.tmp &&
ssh hostname mv /home/user/backup.tar.gz.tmp /home/user/backup.tar.gz

Method 2: rsync Alternative

rsync -azP --inplace /tmp/backup.tar.gz hostname:/home/user/

For NFS-mounted directories:

ssh hostname "cat > /home/user/backup.tar.gz" < /tmp/backup.tar.gz

For EXT4 filesystems with strict atime:

scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
/tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

Check sshd_config for these parameters:

# /etc/ssh/sshd_config
UsePAM yes
StrictModes yes
AllowTcpForwarding yes

When executing the command:

scp /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

The transfer appears successful with progress indicators, yet the destination file's metadata (timestamp and size) remains unchanged from the previous version. This suggests either:

  1. A silent failure during transfer
  2. Filesystem-level permission issues
  3. Caching mechanisms interfering

Add verbose flags to inspect the transfer process:

scp -vv /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

Key items to check in output:

  • Successful authentication sequence
  • Actual bytes transferred count
  • Final confirmation messages

On some network filesystems (NFS, CIFS), timestamp updates may lag. Verify actual content changes with:

ssh hostname "md5sum /home/user/backup.tar.gz"
md5sum /tmp/backup.tar.gz

Method 1: Pre-deletion

ssh hostname "rm -f /home/user/backup.tar.gz"
scp /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

Method 2: Using rsync instead

rsync -avz --progress /tmp/backup.tar.gz hostname:/home/user/
Location Required Permission
Source file Read (0400)
Dest directory Write + Execute (0300)
Dest file (if exists) Write (0200)

1. Strace the scp process:

strace -f -o scp_debug.log scp /tmp/backup.tar.gz hostname:/home/user/backup.tar.gz

2. Check filesystem mount options on destination:

ssh hostname "mount | grep /home"