Hello Everyone, in this post I will discuss about accessing FTP Servers with Python.
To show you some examples of FTP, I will use the 'ftp.redhat.com'
Before I proceed, a small note here, till now we have seen that we import modules by typing "import modulename", well thats correct, but with this statement we are importing all the functions of the Module, even those which we are not using in the program, so its RAM consuming. there Is another way to import specifically whatever function we need from the Module by typing "from Modulename import specific_function"
>>> from ftplib import FTP
>>> ftp =FTP('ftp.redhat.com') <--creating a connection to redhat FTP server
>>> ftp.login() <--since logging in without username and password, there is no arguments passed here, if the login had to use a username and password, the statement ud have been ftp.login('username' 'password')
'230 Login successful.'
>>> d = 'redhat/linux' <--setting a directory path
>>> ftp.cwd(d) <--change the directory
'250 Directory successfully changed.'
>>> print ftp.dir() <--To see the contents of the directory
-rw-r--r-- 1 ftp ftp 131 Dec 20 2005 README
drwxr-xr-x 3 ftp ftp 4096 Feb 21 05:44 beta
drwxr-xr-x 6 ftp ftp 4096 Jun 14 2007 eal
drwxrwsr-x 14 ftp ftp 4096 Jul 25 2011 enterprise
drwxr-xr-x 2 ftp ftp 4096 Feb 12 2006 preview
drwxr-xr-x 2 ftp ftp 4096 Dec 03 2008 rawhide
drwxrwsr-x 4 ftp ftp 4096 Sep 26 2008 updates
None
>>> help(ftp)
[Try this out, as its a huge output, try to understand the functions of the Module]
There is another FTP library that is yet more powerful and robust, but external is the chilkat Module, you can go to http://www.chilkatsoft.com/ and have a look.
Well thats all for this Post. Keep Practicing, I hope you are enjoying them. Don't forget to check my next post.
Thank You!
0 comments:
Post a Comment