Link to home
Start Free TrialLog in
Avatar of ratnaprasad123
ratnaprasad123

asked on

Need a script for for SFTP

Hi ,
   I am looking for a shell script on linux for copying(SFTP)  a file from remote system under a directory . When we run the scripts next time it should only copy (SFTP) new created files only .
 Any examples would be appreciated .

Regards
Avatar of pjedmond
pjedmond
Flag of United Kingdom of Great Britain and Northern Ireland image

I'd recommend using rsync over ssh for this - so much simpler and saves complexity! No need to re-invent the wheel!

Example:
rsync -Cavz -e ssh root@server.ip.net:/home /my/backup/dir/ | tee -a result.log

BAsically, this backs up all changed files from server.ip.net /home directory to a local backup directory, and records info in a result.log file

All you need then is the sshd running on the target.

HTH:)


Avatar of ratnaprasad123
ratnaprasad123

ASKER

well, purpose of copying files is not for backup, after copying, a script  will  process the files and delete from the foleder.
if i use rsync it will again copy all the files.

There's always loads of ways to do things......and some methods are more complex than others. As it stands, I can put together a fairly complex script to do just what you require....but I'm sure that there are easier ways of doing it! If there is some pattern in the file names, then scp would do the job just as well:

scp root@server.ip.net:/home/mylogs/*Jan2005.log .

for example would copy all of the logs for Jan2005 into the local folder for processing.

If this approach isn't of use, then you need to give more information about what is happening in order to get a sensible solution.

HTH:)
we don't have particular file name pattern, the script has to check what is  the last file, it has successfully down loaded(using time stamp or file name), if there are new files after the last file(time stamp) , it has to be down loaded, the last file down loaded should get updated.

ASKER CERTIFIED SOLUTION
Avatar of pjedmond
pjedmond
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your comments i have recieved some good inputs from you.