How to copy a file from remote server and preserve timestamp

Hi

How to copy a file from remote server and preserve timestamp. Please not, i have to pass username and password to connect to the remote server in the shell script.

Can this be achieved with simple ftp ? are there any options in ftp ?

Thanks

Use tar command before transfer, then un-archieve those file at destination.

rsync -Pav user@host:/dir/to/cpy/ /dir/to/cpy/to/

It cannot be done easily with "ftp". You would need to process a directory listing which is not at all easy or to ensure that filenames include timestamps.

As other posters imply there are other methods. You will need to know about both Operating Systems and whether you have useful tools like "scp", "rcp" or whatever.

In most cases "ftp" is actually a last resort. It is useful transferring files between incompatible computer systems or perhaps where you have no control over the remote system and they only offer "ftp".

Agree.

I would still recommend to use rsync in the archive mode. This preserves pretty much EVERYTHING and does a damn nice job at doing it.