I currently have a bash script that downloads files from an FTP Site. I would like to modify the script to keep a manifest of every file it downloads and only download any new files that are not in the manifest. Is there a way to do this in bash or am I pushing the limitations of what bash can actually do?
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
My suggestion would be to go grab the list of files that you might want to download, compare that to your manifest, then download the ones not in the manifest. Something like this should work:
Of course, you'll need to change
filelist.txt
andfilenames.txt
to include an appropriate path. Also, change theecho
command to add the filename to another file or variable that you'll use to do the actual download.Here's an explanation of what's going on:
The first three lines use
ftp
to grab a list of files (You'll want to change the*
to point to the correct directory.)The
cat
line parses the output of the ftpls
command to grab just the filename part and put it into another file.Then the while loop goes through the list of files and uses grep to see if the filename exists in the manifest file. If it doesn't, you can then download it and add it to the manifest.
Let me know if you have any questions.
Hope this helps!