0

I am looking for any solution for my problem. I have SFTP access to client's server and I need some script or something else to watch after new files because they are added irregularly. I need this functionality:

When there is a new file on server the script in best case sends an email (but i will be thankful for any other kind of notification).

I can have only SFTP - so no ssh etc... Do you know about anything like this?

1

Given http://manpages.ubuntu.com/manpages/trusty/en/man1/sftp.1.html

  • use the -b option to pass in sftp commands to cd to the remote directory, and list the files (use ls -l or ls -1t)
    • you'll need to set up ssh keys for password-less authentication
  • parse that output to look for new files
  • use sftp again to get the new files.

Use cron to schedule this job every N minutes or hours

  • Thanks, this look great. But there is a small problem - this only gets files from current directory but I need to get all files recursively from all subdirectories. I looked through that manpage but I did not find any hint how to do that. – honza-kasik Jan 23 '15 at 16:29
  • Do you know what the directory hierarchy is? If not, unfortunately the sftp ls does not have a recursive option, so you have your work cut out for you parsing the ls output for files versus directories and descending into subdirectories programmatically. If you do know the dir structure, then you have to program the cd somewhere; ls – glenn jackman Jan 23 '15 at 16:32
  • I only know how many levels I will have to descend. I'll have to create temporary batch file for sftp for each descending... But after all this sounds as a good solution. Thanks :). – honza-kasik Jan 23 '15 at 16:45
0

I was not content with other solutions so I wrote my own script in python which will walk through remote filesystem, saves filepath to database and sends me an email about new entries. You can get it on GitHub!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.