Linux Blog

Easy script to upload to an ftp server

Filed under: Shell Script Sundays — Kaleb at 11:43 am on Sunday, February 10, 2008

This weeks Shell Script Sunday article is a guest post by Kaleb. Kaleb has been helping me out a by writing for me since I have a project for The Linux Blog that I’d like to complete and can’t dedicate as much time to writing right now. So if you get a chance visit his site and drop some comments.

Hello it’s Kaleb from http://kpstuff.servebeer.com again and today I have come to tell you about a little shell script that I wrote. It’s a script that allows for extremely easy and simple uploads to an ftp server.

The script is actually quite simple utilizing just standard bash scripting along with ncftp which is just an ftp client with some special features. So you need to install ncftp in order to use this script.

Gentoo:

emerge -av ncftp

Arch Linux:

pacman -Sy ncftp

Ubuntu:

apt-get install ncftp

After you install that you need to edit the upload.sh file to fit your needs. There are a few variables you need to change such as your username and password for the server, and the server itself. It is fairly simple to configure.

Set the user variable to your username

user="kaleb"

Set the passwd variable to your password

passwd="kalebspass"

Then you need to set the server variable to your server you want to connect to

server="kpstuff.servebeer.com"

Be sure to not precede the url with something like http:// or ftp://

Finally you should set the default directory on the server for your file to be placed into.

DIR="/home/$user"

Use $user for your username

Also if your system is odd you may need to make sure that /usr/bin/ncftpput exists. if it does not you will need to find out where on your system ncftp is and change the variable FTPCOM to suit your system.

Now all you need to do is run “chmod +x upload.sh” or “chmod 755 upload.sh” to make it executable and you are finished.

Usage for this script is quite simple. all you need to do is:

./upload.sh <FILE>

Making sure to replace FILE with the filename of the file you want to upload

And if you want to temporarily send the file to a different directory then you specified in the file.

./upload.sh <FILE> <DIR>

Remember to replace with the file you want to upload and replace

with the directory you want to upload to.

You can obtain the script at this address http://kpstuff.servebeer.com/~admin/scripts/upload.sh . And that is it thank you very much for your time and I hope that this script helps you out and if not at least gives you ideas.

Man Pages for commands in this post »

ncftp

3 Comments »

Comment by danny

December 8, 2009 @ 5:23 pm

the link to upload.sh file is no longer working :(

Comment by kaleb

December 9, 2009 @ 11:01 am

http://www.filedropper.com/upload_4

there you go sorry about that i dont have a place to host it anymore

Comment by TheLinuxBlog.com

December 9, 2009 @ 12:14 pm

I’ll wget it and stick it on this server at some point :)

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>