Automated SCP script passing password to preserve source file timestamp

Hi

My requirement is i want to copy files from remote server to the local server and also i need to preserve the timestamp of the remote file.

By using scp -p , it is working fine in the interactive call but it is not preserving he file timestamp when i use it in the non interactive scp call that is using shell script.

Also, i need to password for scp and for that reason i'm using except.

Interactive Call

scp -p remote_server:file local_directory  #This is working fine

Non Interactive call through shell script ( This copies the file from the remote server but doesn't preserve the timestamp.

#!/bin/ksh
#!/usr/bin
#!/usr/bin/expect --
expect -f -<<EOF
spawn -noecho scp -p remote_server:file local_directory
expect "Password:"
send "$$$$$$$"
expect "\n"
EOF

I don't understand why the "-p" option ignored in the non interactive call.

Please help

Ugh...

That you're having to shoehorn a stored plaintext password into scp's otherwise secure authentication system with expect is a subtle hint, writ in mile-high flashing neon letters: You're not supposed to do this. It's designed to stop you doing this for security reasons, use pre-shared keys instead -- it's what they're there for. There's instructions for it plastered all over the internet. They do exactly what you want except they don't have the security problems of storing a plaintext password, and don't have the poor reliability and extra wait and extra software requirements of an interactive input manually brute-forced with expect.

Testing it here, copying from a remote host with scp -p does indeed preserve the timestamp, and without a password given pre-shared keys, and definitely non-interactively, deprived of any sort of terminal. I'd expect it to be an expect weirdness, or perhaps an odd version of ssh.