Page 2 of 2 FirstFirst 1 2
Results 11 to 12 of 12

Thread: Shell Script to monitor folder and upload found files via FTP

  1. #11
    Senior Member monk's Avatar
    Join Date
    Jan 2005
    Location
    Tibet
    Posts
    641
    Thanks
    5
    Thanked 42 Times in 37 Posts
    Rep Power
    14

    Default

    The above doesn't always work so you can try following code:
    Code:
    #!/bin/sh
    
    # Configure variables at the begining of the script
    MONITOR_DIR=/var/www/web12/web/php-site-monitor/files
    TMP_DIR=/var/www/web12/web/php-site-monitor/files/tmp
    SUCCESS_DIR=/var/www/web12/web/php-site-monitor/files/success
    FAILED_DIR=/var/www/web12/web/php-site-monitor/files/failed
    FILE_EXT=mp4
    
    # FTP variables
    FTP_HOST=upload-ftp.simplecdn.com
    FTP_USER=myuser
    FTP_PASS=mypass
    FTP_REMOTE_DIR=/
    
    cd $MONITOR_DIR
    
    for f in *.$FILE_EXT; do
    t=$f.current
    echo "Uploading " $f
    
    ftp -inv $FTP_HOST <<EOF
    user $FTP_USER $FTP_PASS
    binary
    cd $FTP_REMOTE_DIR
    put $f
    lcd /tmp
    get $f $t
    get 
    bye
    EOF
    
    if [ -f /tmp/$t ]
    then
    	echo "FTP worked :)"
    	rm -f /tmp/$t
    else
    	echo "FTP of $f did not work :("
    fi
    done
    May the force with you!

  2. #12
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Default

    How about this code?

    Code:
    #!/bin/sh
    
    # Configure variables at the begining of the script
    MONITOR_DIR=/var/www/web12/web/php-site-monitor/files
    TMP_DIR=/var/www/web12/web/php-site-monitor/files/tmp
    SUCCESS_DIR=/var/www/web12/web/php-site-monitor/files/success
    FAILED_DIR=/var/www/web12/web/php-site-monitor/files/failed
    FILE_EXT=flv
    
    # FTP variables
    FTP_HOST=upload-ftp.simplecdn.com
    FTP_USER=myuser
    FTP_PASS=mypass
    FTP_REMOTE_DIR=/
    
    cd $MONITOR_DIR
    COUNT_FILES=$(ls -l *.$FILE_EXT | grep ^- | wc -l)
    
    if [ $COUNT_FILES -gt 0 ]; then
    
    echo "A total of" $COUNT_FILES "file(s) found.";
    echo "Creating TEMP directory:" $TMP_DIR/$PROCCESS_ID_DIR;
    
    mkdir $TMP_DIR/$PROCCESS_ID_DIR
    
    for f in *.$FILE_EXT; do
    echo "Moving file:" $f "to:" $TMP_DIR/$PROCCESS_ID_DIR;
    mv $f $TMP_DIR/$PROCCESS_ID_DIR
    done
    
    cd $TMP_DIR/$PROCCESS_ID_DIR
    
    for f in *.$FILE_EXT; do
    echo "Uploading file via FTP:" $f
    ftp -in $FTP_HOST <<EOF
    user $FTP_USER $FTP_PASS
    binary
    cd $FTP_REMOTE_DIR
    put $f
    bye
    EOF
    
    if [ $? -eq 0 ]
    then
    	echo "FTP File Upload Completed:" $f
    	mv -f $f $SUCCESS_DIR
    else
    	echo "FTP File Upload Failed:" $f
    	mv -f $f $FAILED_DIRs
    fi
    
    done
    
    echo "Uploads completed...";
    echo "Deleting TEMP folder:" $TMP_DIR/$PROCCESS_ID_DIR;
    
    rm -rf $TMP_DIR/$PROCCESS_ID_DIR
    
    else
    
    echo "No files found... Exit!";
    
    fi
    Running that will output something like this:
    Code:
    [root@linux1]# ./shell_php.sh
    A total of 3 file(s) found.
    Creating TEMP directory: /var/www/web12/web/php-site-monitor/files/tmp/2010-07-23_22-25-15
    Moving file: test1.flv to: /var/www/web12/web/php-site-monitor/files/tmp/2010-07-23_22-25-15
    Moving file: test2.flv to: /var/www/web12/web/php-site-monitor/files/tmp/2010-07-23_22-25-15
    Moving file: test3.flv to: /var/www/web12/web/php-site-monitor/files/tmp/2010-07-23_22-25-15
    Uploading file via FTP: test1.flv
    KERBEROS_V4 rejected as an authentication type
    FTP File Upload Completed:  test1.flv
    Uploading file via FTP: test2.flv
    KERBEROS_V4 rejected as an authentication type
    FTP File Upload Completed:  test2.flv
    Uploading file via FTP: test3.flv
    KERBEROS_V4 rejected as an authentication type
    FTP File Upload Completed:  test3.flv
    Uploads completed...
    Deleting TEMP folder: /var/www/web12/web/php-site-monitor/files/tmp/2010-07-23_22-25-15
    [root@linux1]#
    Any recommendations?

    Does anyone knows how to get rid of the message: "KERBEROS_V4 rejected as an authentication type" in the output or should I ignore it?
    Last edited by pulsorock; 24th July 2010 at 08:04 AM.

Page 2 of 2 FirstFirst 1 2

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 15
    Last Post: 13th December 2009, 01:54 AM
  2. Linux Shell Script to upload log files to Windows XP based FTP Server
    By stefanuscyberia in forum Shell scripting
    Replies: 6
    Last Post: 18th November 2009, 01:29 PM
  3. Shell script to monitor syslog.log
    By spabba in forum Shell scripting
    Replies: 1
    Last Post: 24th March 2009, 05:08 PM
  4. Replies: 1
    Last Post: 25th October 2007, 01:44 PM
  5. i need a script to delete one folder with files on my ftp
    By silver_ch in forum Shell scripting
    Replies: 1
    Last Post: 27th March 2007, 10:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41