?
Solved

Need a script for for SFTP

Posted on 2005-03-31
6
Medium Priority
?
423 Views
Last Modified: 2011-04-14
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
0
Comment
Question by:ratnaprasad123
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:pjedmond
ID: 13674507
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:)


0
 

Author Comment

by:ratnaprasad123
ID: 13674690
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.

0
 
LVL 22

Expert Comment

by:pjedmond
ID: 13675375
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:)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ratnaprasad123
ID: 13675686
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.

0
 
LVL 22

Accepted Solution

by:
pjedmond earned 2000 total points
ID: 13676131
The bit that I find worrying here is what happens if the last file is still being used when you transfer the files. rsync handles a lot of the additional complexity. Plus, I assume that you want the scripts *only* running from one side of the connection otherwise you start having synchronisation problems.

The main obstacle that I can't overcome at the moment relates to verifying the properties(modification dates) of the files on the remote PC via ftp, or indeed scp without doing something *really* messy to copy the files over preserving their modification dates, and then analysing this info locally. This means that my approach to this would be to use the rsync method already mentioned, and instruct the script to analyse the data only to look at files newer than the last run date/time. The disadvantage of this is that you use some extra space to store all the older files as well, but you can manually/or using cron daemon 'prune' these files every so often.

Unless you arrange for some methodical naming process on the remote system, I can't see any clean/obvious way to go about this other than that mentioned above. Perhaps leave the Q open to see if anyone can come up with a better idea, or examine your process and see whether any modifications can be made to make it more user friendly...e.g. have the files on a shared network drive etc.

HTH:)
0
 

Author Comment

by:ratnaprasad123
ID: 13684624
Thanks for your comments i have recieved some good inputs from you.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question