?
Solved

Need a script for for SFTP

Posted on 2005-03-31
6
Medium Priority
?
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

764 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