Created
December 11, 2012 13:22
-
-
Save anonymous/4258503 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #Sets the IP address of the ftp server | |
| SERVER=192.168.56.50 | |
| FOLDER=/root/sftp | |
| #this grabs the list of files available on the server | |
| FILE_LIST=`sftp $SERVER << EOF | |
| cd sftp | |
| ls | |
| quit | |
| EOF` | |
| echo $FILE_LIST > temp_file_list | |
| #this is used to remove everything except xml files | |
| for DOWNLOAD_FILE in `cat temp_file_list` | |
| do | |
| echo $DOWNLOAD_FILE |grep .xml >> download | |
| done | |
| #ensure that the files are sorted properly | |
| sort download > download_list | |
| #get the local list | |
| ls |grep .xml | sort > local_list | |
| # checks to see which files are on the server that are not | |
| # on the local machine | |
| DIFF=`diff local_list download_list | cut -c3- |grep .xml` | |
| #check to see if each file in the server's list exists on the local maching | |
| if [ `echo $DIFF` =="" ] | |
| # If there are no differences in the folder assume there is nothing | |
| # new to transfer | |
| then | |
| echo No New Files to transfer | |
| else | |
| for SERVER_FILE in $DIFF | |
| do | |
| #if the file does not exist, grab it | |
| sftp $SERVER << EOF | |
| cd sftp | |
| put $SERVER_FILE | |
| exit | |
| fi 2>/dev/null | |
| #remove the temporary file lists | |
| rm local_list | |
| rm temp_file_list | |
| rm download | |
| rm download_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment