Setting up FTP Server in ubuntu

Want to access your files from anywhere in your network(LAN)? You can setup your PC/Laptop as an FTP server & then access your files from anywhere within the network.

Vsftpd is the most easy ftp server to setup.
Installing vsftpd:
From Synaptic:
Goto Synaptic Package Manager. Search for “vsftpd”. Mark for installation & apply. or
From terminal typeout:
$ sudo apt-get install vsftpd

There are various settings that needs to be done before starting. These are specified in the configuration file for vsftpd located in “/etc/vsftpd.conf”. The default configuration is a little bit paranoid, not so usable for file sharing.
We can edit this, but lets keep a copy of the original somewhere.
$ sudo cp /etc/vsftpd.conf /etc/vsftpd_conf_original.txt

Now,we start editing the options:
1. Open the configuration file using:
$ sudo gedit /etc/vsftpd.conf

2. I have used the following configuration for my FTP server. It allows anonymous access and anonymous users are jailed(thats the term used) to the chroot(eg. /home/ftp will be the default) directory. Enable/ Uncomment these lines in vsftpd.conf:
(Replace “abhishek” with your username on linux)
listen=YES
anonymous_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
xferlog_enable=YES
chown_uploads=YES
chown_username=abhishek
ftpd_banner=Welcome to Abhishek's FTP service.
chroot_local_user=NO
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd

Keep other options as default.
Save. Restart the FTP server (as below).

3. To run this server:
sudo /etc/init.d/vsftpd start
To stop it:
sudo /etc/init.d/vsftpd stop
To restart it:
sudo /etc/init.d/vsftpd restart

4. You can make changes to the configuration file anytime. But remember to restart the ftp server, using the above command, to apply the changes.
After this your ftp server should start functioning.

5. To Allow FTP access to files outside the home directory chroot, see the Reference#2 below.

To access the files, there are many ways.
1. Open a browser like Internet explorer, firefox, opera etc. Type the url as
“ftp://servername” for anonymous access. e.g. ftp://10.117.113.24 or
“ftp://username@servername” for login. e.g. ftp://abhishek@10.117.113.24
Then the files will get listed.
In this method, you can only download files from the FTP server.

2. Using gFTP- Install gFTP from Synaptic Package Manager. Run it from Applications>Internet>gFTP. Enter the username and password to login(For anonymous access, give username as “anonymous” and any relevant password). Then start sharing files.

3. Using Command Prompt-
In windows, open command prompt or
In Linux, open terminal
and type:
ftp servername or
ftp ftp://username@servername

To download a file use:
ftp>get remote-file [local-file]
To upload:
ftp>put local-file [remote-file]
To close connection:
ftp>close
For other commands use Ref#3 below.

Some Reference posts that will be helpful:
1. Howto: Easy FTP with vsftpd
2. Allowing FTP access to files outside the home directory chroot
3. List of FTP commands for the “Microsoft command-line FTP client” or “Linux terminal – FTP client”

Advertisements

Getting Ubuntu back after windows install

Many of us might have faced this problem–
I have ubuntu installed. Now if i install windows (any version), then my ubuntu Bootloader(Grub) is lost & replaced by windows bootloader. And Windows doesn’t recognise Linux. So it effectively means we dont have access to ubuntu any more.
But there is a solution. Install your windows wherever you want(in any logical drive on your HDD except ubuntu drive). Then follow the following procedure to get the Ubuntu Bootloader (Grub) back with your new windows option.

1. Boot from Ubuntu CD
2. In the Live CD mode itself, open terminal & type:
$ sudo grub
you’ll get the grub command prompt as
grub>
3. type:
$ find /boot/grub/stage1
you’ll get ans like-
root (hd0,7)
4. After this, type:
$ setup (hd0,7)
remember to this (hd0,x) same as you get in the previous step
This’ll install grub.
And in my case this was it. I was able to start ubuntu & windows both from Grub boot menu.

If this didnt solve your problem, then
5. Restart into windows
6. download a software called easyBCD, its free. And install it.
7. When you run it, u’ll see a boot menu
Select the “Add entry” option.
8. Enter name od OS as “Ubuntu”(or anything that u want to appear on the boot menu)
9. Select loader as “Grub” & select the partition where ubuntu is installed.
10. Click apply & restart.
You will see the ubuntu partition

Installing opencv in linux(Ubuntu) from .tar.gz file

I installed opencv for g++ in Ubuntu 9.04 (jaunty) through the following procedure.
Things to know before starting installation:
i. This installation needs a C++ compiler like “g++”(which is most commonly used). So install g++ first using Synaptic.
ii. Type out the following code to know the version of GTK+ installed on ur pc.

$ dpkg -l | grep libgtk

GTK is graphical user interface library. OpenCV requires GTK+ 2.0 or higher for displaying images.
This command should give o/p something like:

libgtk-directfb-2.0-0 2.16.1-0ubuntu2

If not, then u need to install the libraries for GTK+ 2.0 first, then start with this opencv installation.

If both g++ & GTK+ 2.0 are there then proceed as follows:
1. extract the opencv.tar.gz(right click> extract) into a folder, say “opencv”
2. copy that folder to /home
3. open terminal & cd to that folder
$ cd /home/opencv

4. type out:
./configure –prefix=/home/opencv –enable-apps –with-gnu-ld –with-x

If g++ is not installed, error may come as:
checking for C++ compiler default output file name… configure: error: C++ compiler cannot create executables
See `config.log’ for more details.

If you check this config.log, it says that g++ compiler not found. So you need to install it first.

5. Assuming all goes well, the configuration program will end with a prompt to ‘make’. Do that and then register the libraries (make install).

6. sudo make
Wait patiently, it’ll take time.
7. sudo make install
8. go to /home/ using
$ cd ~

9. Open .bashrc file using your favourite editor, eg:
$ gedit .bashrc

10. Append the following 2 lines to it:(before adding check whether these 2 paths respectively contain “lcxcore” & “opencv.pc”. If no, findout the path where these two files are & then modify the path accordingly)

export LD_LIBRARY_PATH=/home/opencv/lib
export PKG_CONFIG_PATH=/home/opencv/
and save & close .bashrc

11. Close the terminal & reopen(as this process requires relogin of the terminal)
12. Type the following command to check the location of opencv
pkg-config –cflags opencv

o/p:
-I/home/opencv/include/opencv

13. Type the following command to check the location of opencv lib files
pkg-config –libs opencv

o/p:
-L/home/opencv/lib -lcxcore -lcv -lhighgui -lcvaux -lml

14. To compile & build your code, cd into the folder where u have your program(*.cpp) & do:
$ g++ -I/home/opencv/include/opencv -L/home/opencv/lib -lcv -lcxcore -lcvaux -lhighgui -lm”

15. To run: $./a.out
or $./a.out

If things like the following appear-
recompile libraries using Windows,GTK+ or Carbon
Terminating blah blah..

Then goto synaptic Package Manager & install the library files for GTK+.
Then restart from step#3

16.Now lets simplify the above big command by making a shortcut for it:
go to your local home directory(cd /home/) and open the .bashrc file using gedit(the file will be hidden). Append the following to the file:

alias gcv=”g++ -I/home/opencv/include/opencv -L/home/opencv/lib -lcv -lcxcore -lcvaux -lhighgui -lm”

and save. Close the terminal and open it again.

17. Now onwards, to compile, build & run a program, u can simply do:
$ gcv filename.cpp
$ ./a.out img_name.extension

Enjoy!!!

Installing OpenCV on Linux (Ubuntu)

Earlier i was using openCV with Microsoft Visual C++ 6.0. But let me tell you, it crashed a lot. Every time i needed to close the process from Task Manager. Then i decided to somehow install OpenCV for my ubuntu.
After searching and trying a lot for this, i was finally able to use opencv in GNU compiler(g++ or gcc).
Synaptic Package Manager has simplified the life to a great extent. OpenCV is now available in the ubuntu repositories.
Though there are some problems related to ‘ffmpeg’, i needed opencv for image processing only. So i have not mentioned here what to do about ‘ffmpeg’.

Things to know before starting installation:
i. This installation needs a C++ compiler like “g++”(which is most commonly used). So install g++ first using Synaptic or by following command at the terminal–

$ sudo apt-get install g++

ii. OpenCV requires GTK+ 2.0 or higher for displaying images. GTK is graphical user interface library. Type out the following code to know the version of GTK+ installed on ur pc.

$ dpkg -l | grep libgtk

This command should give o/p something like:

libgtk-directfb-2.0-0 2.16.1-0ubuntu2

If not, then u need to install the libraries for GTK+ 2.0 first, then start with this opencv installation.
To install GTK+ 2.0 libraries, type out the following command:

$ sudo apt-get install libgtk2.0-dev

If both g++ & GTK+ 2.0 are there then proceed as follows:

I am using Ubuntu 9.04 (Jaunty Jackalope) and i did the following steps to install & configure OpenCV(ver 1.0.0.6) successfully:

1. Go to Synaptic Package Manager (System> Administration> Synaptic Package Manager)
2. Search for “opencv” and install the main “opencv” package and the following lib files:
libcv
libcv-dev
libcvaux
libcvaux-dev
libhighgui
libhighgui-dev
opencv-doc
(‘python-opencv’ not required).
(you can also install opencv directly from the terminal by “sudo apt-get install” the above lib files
3. After installing all the packages, open a terminal & type this code:

export LD_LIBRARY_PATH=/home/opencv/lib
export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig

The above ones are default paths for the opencv libraries.
4. For testing:
Create a new folder & a file “hello.cpp” in it using any text editor & type this code in it:

#include < cv.h > /* required to use OpenCV */
#include < highgui.h > /* required to use OpenCV's highgui */
#include < stdio.h >

int main(int argc, char *argv[]) {
IplImage* img=0; /* pointer to an image */
printf("Hello\n");
if(argv[1] != 0)
img = cvLoadImage(argv[1], 0); // 1 for color
else
printf("Enter filename\n");
if(img != 0) {
cvNamedWindow("Display", CV_WINDOW_AUTOSIZE); // create a window
cvShowImage("Display", img); // show image in window
cvWaitKey(0); // wait until user hits a key
cvDestroyWindow("Display");
}
else
printf("File not found\n");
return 0;
}


5. To check the path where opencv & other lib files are stored, do:

$ pkg-config --cflags opencv

(output will come as)
-I/usr/include/opencv

$ pkg-config --libs opencv

(output will come as)
-lcxcore -lcv -lhighgui -lcvaux -lml

These paths are needed to compile your opencv programs, as given in the next step.

6. To compile & run:

$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp
./a.out img

where “img” is the name of any image within the same folder with extension.
You should be able to see “Hello” and the image in a different window.

-> If this runs, Congrats! now you can run any C/C++ program with opencv lib.
Else, try

$ export PATH=$HOME/usr/bin/:$PATH

and go to step3 again.

7. Now lets simplify the above big command by making a shortcut for it:
go to your local home directory(cd /home/) and open the .bashrc file using gedit(the file will be hidden). Append the following to the file:

alias gcv="g++ -I/usr/include/opencv -lcv -lcxcore -lcvaux -lhighgui -lm"

and save. Close the terminal and open it again.(as this process requires relogin of the terminal)

8.Now, go to directory containing a sample program & do

$ gcv filename.c && ./a.out
or
$ gcv filename.c
$ ./a.out input_img.jpg

As you can see the commands now become similar to $cc filename.c, $./a.out which are used normally for compiling and executing C programs.

****************************
Some ways to check whether all lib files are installed-
1. $ apt-cache search opencv
returns:
libcv-dev - development files for libcv
libcv0.9-0c2 - computer vision library
libcvaux-dev - development files for libcvaux
libcvaux0.9-0c2a - computer vision extension library
libhighgui-dev - development files for libhighgui
libhighgui0.9-0c2 - computer vision GUI library
opencv-doc - OpenCV documentation and examples


—————————————————————————
If you want to install openCV from a .tar file, refer this article:
Installing opencv in linux(Ubuntu) from .tar.gz file
Other helpful links on this topic:
http://ivkin.net/2009/11/installing-opencv-2-0-on-ubuntu-9-10-karmic-koala/