• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Saturday, February 27, 2010

Posted by venu k
11 comments | 9:27 AM

#!/bin/bash
# SCRIPT : upload.sh
# USAGE : ./upload.sh [-d remote directory path] -f "File-to-upload"
# -d option is optional by default it takes servers home dir
# or
# ./upload.sh "Filename-to-upload"
#
# PURPOSE : Upload file to remote ftp server.

############### DEFINE FUNCTIONS HERE ##############

Usage()
{
echo " USAGE "
echo " $0 [-d \"Remote Directory Path\"] -f \"Filename-to-upload\""
echo "-------------------------- or -----------------------------"
echo " $0 Filename-to-upload"
exit 1
}

################# ARGUMENTS CHECKING #################

while getopts d:f: choice
do
case $choice in
d) Dname=$OPTARG;;
f) Fname=$OPTARG;;
esac
done

[ $# -eq 1 ] && Fname=$1
[ -z $Dname ] && Dname="/" #change it to suit
[ -z $Fname ] && echo "Bad Arguments" && Usage

[ ! -e $Fname ] && echo "$0: $Fname no such file" && exit 1

############### DEFINE VARIABLES HERE ################

Server="ftp.checksoftware.com" #Remote ftp server.
Username="anonymous" #Remote ftp user name.
Password="venuk@gmail.com" #Remote ftp Password.

# change above to suit

############### MAIN PROGRAM STARTS HERE #############

# Remove comment lines within the here document before run the script

ftp -n $Server <<ServerEnd
user "$Username" "$Password"

# binary command Set the file transfer type to support binary file
# transfer.So you can transfer all type of files.

binary

# hash command is used for printing hash-sign("#") for each data block
# transferred. The size of data block is system dependent.In my box it
# is 1024 bytes. hash command is a toggle switch, by default it is set
# off most systems.

hash # comment it if you don't need it

cd $Dname

# pwd command prints current directory on the remote host. This shows
# your file is uploading to which directory.

pwd # comment it if you don't need it

put "$Fname"
bye
ServerEnd

exit 0

OUTPUT:

[root@www ~]# ./upload.sh
Bad Arguments
USAGE
./upload.sh [-d "Remote Directory Path"] -f "Filename-to-upload"
-------------------------- or -----------------------------
./upload.sh Filename-to-upload
[root@www ~]# ./upload.sh -f samplepic.jpg -d /incoming
Hash mark printing on (1024 bytes/hash mark).
257 "/incoming" is current directory.
###############################################
[root@www ~]# ./upload.sh samplepic.jpg
Hash mark printing on (1024 bytes/hash mark).
257 "/" is current directory.
samplepic.jpg: Permission denied