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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting preserving the timestamp of a file when copied from remote server to local server using ftp
# 1  
Old 05-14-2010
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.

Code:
 
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
# 2  
Old 05-14-2010
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.
# 3  
Old 05-14-2010
Thanks Zaxxon.

I tried this -

Code:
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
# 4  
Old 05-14-2010
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
# 5  
Old 05-14-2010
Thank u so much... I tried this and its working fine for me...

Code:
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
# 6  
Old 05-14-2010
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

2. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

3. Shell Programming and Scripting

How to create a file in remote server from local server?

hi, can anyone tell me how can i store the names of a file that are in remote server to a file and then get the file that contains the name in local server? there is a remote server where 5 files are present , say a.txt b.txt c.txt d.txt e.txt i want to write a script in my local... (4 Replies)
Discussion started by: Little
4 Replies

4. Shell Programming and Scripting

Check files copied from remote server

There is a process which copy files form unix a to unix b I would like to check whether all files copied from a to b or not ,and list which are the missing files. Is there a command to check like that (3 Replies)
Discussion started by: lalitpct
3 Replies

5. UNIX for Advanced & Expert Users

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 (4 Replies)
Discussion started by: skumar75
4 Replies

6. Shell Programming and Scripting

Can a script runned in local server access remote server?

Hi, Im creating a script that is supposed to run commands on remote server using sftp. My script is as below: #!/bin/ksh sftp remote_server mypassword cd /u08/mydir/allfiles mget * .. But this is what I got when I runned the script: Connecting to remote server...... (3 Replies)
Discussion started by: luna_soleil
3 Replies

7. Shell Programming and Scripting

Transfer file from local unix server to remote server

want to remove this thread. thanks (2 Replies)
Discussion started by: indira
2 Replies

8. HP-UX

Transfer file from local unix server to remote server

want to remove the thread thanks (2 Replies)
Discussion started by: indira
2 Replies

9. Shell Programming and Scripting

Dowloading a File from FTP Server to a local Server where User Id's are different

Hi, The Setup is like this. I'm connecting to Unix machine from my local machine. After connecting to Unix M/c, i need to connect FTP server. Am successful in connecting to FTP server, but am not able to download the file from the ftp server to my local machine. I have different user id's and... (1 Reply)
Discussion started by: ranjith_taurean
1 Replies

10. Shell Programming and Scripting

FTP multiple files from remote server to local server

Hi, I am facing a weired problem in my FTP script. I want to transfer multiple files from remote server to local server everyday, using mget * in my script. I also, want to send an email for successful or failed FTP. My script works for file transfer, but it don't send any mail. There is... (2 Replies)
Discussion started by: berlin_germany
2 Replies
Login or Register to Ask a Question