Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- server=""
- user=""
- pass=""
- loginScript="quote USER $user
- quote PASS $pass"
- function send {
- filelocal=$1
- fileremote=$1
- echo Sending $fileremote
- ftp -n $server > /dev/null <<EOF
- $loginScript
- put $file $fileremote
- quit
- EOF
- }
- function makedir {
- dirToCreate=$1
- ftp -n $server > /dev/null <<EOF
- $loginScript
- mkdir $dirToCreate
- quit
- EOF
- }
- function tree {
- echo Creating structure
- for i in `find -type d`
- do
- makedir $i
- done
- }
- function sync {
- echo Doing a full sync
- clean
- tree
- push
- }
- function push {
- echo pushing changes
- for i in `find -type f`
- do
- send $i
- done
- }
- function emptydir {
- dirToEmpty=$1
- echo Deleting everthing inside of $dirToEmpty on remote
- ftp -n $server > /dev/null <<EOF
- $loginScript
- prompt
- cd $dirToEmpty
- mdelete *
- quit
- EOF
- }
- function ls {
- dirToLs=${1-'.'}
- out=`ftp -n $server <<EOF
- $loginScript
- cd $dirToLs
- dir
- EOF
- `
- echo "$out" | cut -c40-
- }
- function clean {
- currentDir=.
- echo Cleaning everthing
- function delete {
- currentDir=$1
- echo Deleting directory $currentDir on remote
- emptydir $currentDir
- for i in `ls $currentDir`
- do
- delete $currentDir/$i
- done
- ftp -n $server > /dev/null <<EOF
- $loginScript
- rmdir $currentDir
- EOF
- currentDir=`echo $currentDir | sed -e 's/\(.*\)\/.*$/\1/g'`
- }
- delete $currentDir
- }
- function help {
- echo "./ftp.sh [send|sync|clean|help]
- clean deletes all files on remote
- help show this
- makedir <name> makes a directory
- send <filename> pushes a file to remote
- sync pushes all files to remote
- tree build the base tree
- "
- }
- ${1-false} || echo "Unrecognised command: ${1-none} `help`"
Add Comment
Please, Sign In to add comment