preserving the timestamp of a file when copied from remote server to local server using ftp

Hi,

I need to copy few files from remote server to local server.
I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed.

 
ftp -nvi svag1017 << EOD
user username passwd
bin
cd /users/users-03/p494856/learning
mget file1 file2 file3 
close
bye
EOD

when i run this, all the files are copied to the local server but the timestamp shows the time, when these files were copied. But i need these files with the timestamp same as in the remote server.

Could someone help me to solve this?

Regards
Arun

If possible you might want to switch to scp or sftp (I'd go for scp) since it offers encrypted file transfer and public key authentication as well as other helpful options.
Should you decide to go this way, there is plenty of guides on the web and in this forum how to set up a public key authentication with ssh/scp/sftp.
scp has a -p flag that will preserve mtime, atime and modes.

I am not aware of a similar option for plain ftp.

Thanks Zaxxon.

I tried this -

scp -p p494856@svag1017:/aorp02/orp/appdata/rprt/*.csv .

and the output came as I expected. But it asks for the password while executing this script.
I need this script to be executed non-interactively. Will it be possible to mention in the password anywhere in the script, so that it will execute automatically.

Regards
Arun

Nope. As already written, for this purpose you set up passwordless authentication by generating keys (ssh-keygen) without entering a password and add the public key of the machine that should be granted permission to it's ~/.ssh/authorized_keys. It is bad practice to use a passwords unencrypted inside files.

As said there are plenty guides on the web easy to find as well via the search function of this forum. Use the patterns "ssh passwordless authentication" on Google for example. This is the 1st hit I got:
SSH login without password

Thank u so much... I tried this and its working fine for me...

scp ~/.ssh/id_rsa.pub remote.server.com:.ssh/authorized_keys2

Should i need to execute this command for each remote server i need to connect or is there any possible way so that in one command I can list out all the remote servers so that it will create the key?

Regards
Arun

Afaik you have to add the key to/for all servers each manually or write a while loop reading in a file with the hostnames for example.

If you have to do some tasks on a bunch of hosts via ssh, you might have a look at Automating ssh and scp across multiple hosts