SoFunction
Updated on 2025-03-10

Use scp command to implement file upload code in shell


#!/bin/sh
 
HOME='/cygdrive/d/public_html/myproject'
 
## Package local code first
## Exclude the following files: *.svn, *.bat, , cache
## If there are many files that require exclude, you can use the parameter --exclude-from=FILE
## Write a file line to FILE
cd $HOME
tar jcf .bz2 *   \
    --exclude=*.bat     \
    --exclude=*.bz2     \
    --exclude=*.gz      \
    --exclude=.svn      \
    --exclude=cache     \
    --exclude= \
 
## Upload files via SCP
scp .bz2 user@:/home/public_html/myproject/.bz2
 
## Execute remote ssh command
## Another script was executed here
ssh user@
 "
 cd /home/public_html/myproject
 tar jxf .bz2
 chown -R web:web *
 chmod -R 755 *
 sh
 rm -f .bz2
 "
 
## Delete local files
rm -f .bz2
echo "Everything is done."
 
# Monday January 11, 2010 by Verdana
# vim: set expandtab tabstop=4 shiftwidth=4: