A little bit of Python, FTP and CentOS


Today I will approach the system using few lines of Python code :

– Python code : FTP client

– CentOS server :  FTP server

Let’s get started !

FTP uses 2 port : 21 and (sometimes) 20 if the server is in active mode – or a random port (we’ll see them in this posting)

First of all, you need to install vsftp & ftp on your Server, by using those commands

yum install -y vsftpd #this one is for ftp server
yum install -y ftp #this one is for ftp client
service vsftpd start

Check whether FTP service is listening on port 21

ftp1

Alright, that’s for the server-side, now at your client, open Python IDLE and run this

from ftplib import FTP
f = FTP('ip_address_my_ftp_server')
f.login('anonymous','anonymous') #I'm using anonymous login
#f.quit() #omit this line, I'll explain below

Let’s check the netstat again and you’ll see what’s happening here :

ftp2

 

There you go “113.170.87.128:24567” is my computer’s ip address and the port number which the ftp-server randomized it (passive mode).

And because f.quit() wasn’t executed, so that the connection is still open, that’s why you see the line “ESTABLISHED” above. If f.quit() executed – the connection will close before you can see anything happen.

Try as many time as you can, and take a look at this picture – I was using “f.quit()” to close a connection to the CentOS FTP server :

ftp3

 

Have fun, I will write more about this in the next few days, we’re just scratching the surface, but it’s fun, right?

Facebook Comments

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x