Sep 072010
 

It’s possible to use even more complicated syntax with regular expressions:

I used this in my FTP script for safety surveillor.

case “$1? in
+(start|run) ) /usr/app/startup-script ;;
@([Ss])top ) /usr/app/stop-script ;;
esac

?(pattern1 | pattern2 | … | patternn)
zero or one occurrence of any pattern

*( pattern1 | pattern2 | … | patternn)
zero or more occurrences of any pattern

@( pattern1 | pattern2 | … | patternn)
exactly one occurrence of any pattern

+( pattern1 | pattern2 | … | patternn)
one or more occurrence of any pattern

!( pattern1 | pattern2 | … | patternn)
all strings except those that match any pattern

Sep 052010
 

The passwords have been removed for obvious reasons.

The fucntion works now! I couldn’t figure out how to force the user to input a number for the second argument but I figured out a work-around to force the user to input two arguments. If they don’t it will present a message telling them what they need to do. I also had to add a bogus option (xyzpdq) in front of the user names in the “case” section. For some reason the script ignores whatever is in the first position.

sendtoftp() {
if [ $# -ne 2 ]
then
echo
echo “————————————–”
echo “| Example: sendtoftp ban11 09122010 |”
echo “————————————–”
echo
else

case $1 in
ban11)
HOST=10.65.48.199
USER=ban11
PASSWD=xxxxxx

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
#print -p cd directory
#print -p binary
print -p prompt
print -p ascii
print -p mput ban11*$2*
print -p bye

wait
exit 0
;;
@xyzpdq | ban02 | ban03 | ban04 | ban05 | ban06 | ban07 | ban08 | ban09 | ban10 | ban12 | ban13 | ban14 | ban15 | ban16 | ban17 | ban18 | ban19 | ban20 | ban20 | ban21)

HOST=10.65.48.199
USER=$1
PASSWD=xxxxxxx

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
#print -p cd directory
##print -p binary
print -p prompt
print -p ascii
print -p mput $1*$2*
print -p bye

wait
exit 0
;;
*)
Message=”Usage: sendtoftp username date.”
Message1=”Example: sendtoftp ban12 09012010.”
echo ” ”
echo ” ”
echo $Message ” “$Message1
echo ” ”
echo ” ”
;;
esac
fi
}

Jul 062010
 

On Linux or Unix Systems you can use sftp like this:

sftp -oPort=1234 username@remote.servername.com
After authenticating, the following commands can be used. Any
paths should have quotes if they contain spaces.

Some standard commands and their definitions for command line SFTP include:

?	Get help on the use of SFTP commands.
bye	Close the connection to the remote computer and exit SFTP.
cd	Change the directory on the remote computer.
chgrp	Change the group associated with a computer file (chgrp system foofile).
chmod	Change the permissions of files on the remote computer.
chown	Change the owner of files on the remote computer.
dir	List the files in the current directory on the remote computer.
exit	Close the connection to the remote computer and exit SFTP.
get	Copy a file from the remote computer to the local computer.
help	Get help on the use of SFTP commands.
lcd	Change the directory on the local computer.
lls	See a list of the files in the current directory on the local computer.
lmkdir	Create a directory on the local computer.
ln	Create a symbolic link for a file on the remote computer.
lpwd	Show the current directory (present working directory) on local computer.
ls	Show the current directory on the remote computer.
lumask	Change the local umask value.
mkdir	Create a directory on the remote computer.
progress Toggle display of progress meter.
put	Copy a file from the local computer to the remote computer.
pwd	Show the current directory (present working directory) on remote computer.
quit	Close the connection to the remote computer and exit SFTP.
rename	Rename a file on the remote host.
rm	Delete files from the remote computer.
rmdir	Remove a directory on the remote host (the directory has to be empty).
symlink	Create a symbolic link for a file on the remote computer.
version	Display the SFTP version.
! 	In Unix, exit to the shell prompt, where you can enter commands. Enter exit
	to get back to SFTP. If you follow  !  with a command (e.g., !pwd), SFTP
	will execute the command without dropping you to the Unix prompt.