SHARE
TWEET

Untitled

a guest May 23rd, 2018 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. server=""
  4. user=""
  5. pass=""
  6. loginScript="quote USER $user
  7. quote PASS $pass"
  8.  
  9. function send {
  10.   filelocal=$1
  11.   fileremote=$1
  12.   echo Sending $fileremote
  13.  
  14.   ftp -n $server > /dev/null <<EOF
  15.     $loginScript
  16.  
  17.     put $file $fileremote
  18.     quit
  19. EOF
  20. }
  21.  
  22. function makedir {
  23.   dirToCreate=$1
  24.  
  25.   ftp -n $server > /dev/null <<EOF
  26.     $loginScript
  27.  
  28.     mkdir $dirToCreate
  29.     quit
  30. EOF
  31. }
  32.  
  33. function tree {
  34.   echo Creating structure
  35.  
  36.   for i in `find -type d`
  37.   do
  38.     makedir $i
  39.   done
  40. }
  41.  
  42. function sync {
  43.   echo Doing a full sync
  44.   clean
  45.  
  46.   tree
  47.  
  48.   push
  49. }
  50.  
  51. function push {
  52.   echo pushing changes
  53.  
  54.   for i in `find -type f`
  55.   do
  56.     send $i
  57.   done
  58. }
  59.  
  60. function emptydir {
  61.   dirToEmpty=$1
  62.   echo Deleting everthing inside of $dirToEmpty on remote
  63.  
  64.   ftp -n $server > /dev/null <<EOF
  65.     $loginScript
  66.     prompt
  67.  
  68.     cd $dirToEmpty
  69.     mdelete *
  70.     quit
  71. EOF
  72. }
  73.  
  74. function ls {
  75.   dirToLs=${1-'.'}
  76.  
  77.   out=`ftp -n $server <<EOF
  78.   $loginScript
  79.   cd $dirToLs
  80.  
  81.   dir
  82. EOF
  83. `
  84.  
  85.   echo "$out" | cut -c40-
  86. }
  87.  
  88. function clean {
  89.   currentDir=.
  90.   echo Cleaning everthing
  91.  
  92.   function delete {
  93.     currentDir=$1
  94.     echo Deleting directory $currentDir on remote
  95.  
  96.     emptydir $currentDir
  97.  
  98.     for i in `ls $currentDir`
  99.     do
  100.       delete $currentDir/$i
  101.     done
  102.  
  103.     ftp -n $server > /dev/null <<EOF
  104.     $loginScript
  105.  
  106.     rmdir $currentDir
  107. EOF
  108.     currentDir=`echo $currentDir | sed -e 's/\(.*\)\/.*$/\1/g'`
  109.   }
  110.  
  111.   delete $currentDir
  112. }
  113.  
  114. function help {
  115.   echo "./ftp.sh [send|sync|clean|help]
  116.     clean               deletes all files on remote
  117.     help                show this
  118.     makedir <name>      makes a directory
  119.     send <filename>     pushes a file to remote
  120.     sync                pushes all files to remote
  121.     tree                build the base tree
  122. "
  123. }
  124.  
  125. ${1-false} || echo "Unrecognised command: ${1-none} `help`"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top