Reading Time: 5 mins

Process Automation using Python

Software Applications Development company

Process Automation using Python

In this article, we will be sharing the experience of configuring a FTP Server.

As per our research, we decided to use python for backend. We never had any previous experience in python. So, to start with things, we completed the initial installation process for python. Then we explored ways to develop the code to transfer files from one FTP Server to another. We never found any pre-developed code for our requirement. After days of exploration we realized that it was not that easy to transfer files between two FTP Server directly. Then we did a workaround. We moved all files from the source FTP server (Source server) to a local server and then transfer all files from the local to the end FTP server (Destination Server).

 Software Applications Development

Files transfer between FTP servers

List of FTP Server Tools

List of tools used to accomplish our task. Some of the library files are ftplib, os, sys, shutil, xrld and datetime.

  • ftplib library was used to download and upload files to FTP Server.
  • os and sys library files were used to read, w rite, list the files in local server.
  • Firstly, we downloaded all files from the source FTP Server. Using below code we downloaded all files.

Code snippet:

ftp.retrbinary(“RETR “ + file, open(os.path.join(destination + path, file),”wb”).write). The above code retrieves and writes files in particular path of local server.Then, this code ftp.storbinary(‘STOR %s’ % i, open(os.path.join(FileSend,i), “rb”)) used to upload files from local server to FTP Server.

Initially, we developed a code to download and upload files to the FTP server one file per transfer. But we faced a requirement to dynamically download and upload multiple files from different FTP servers. To simplify things we started to create excel sheets to maintain credentials and file path of FTP servers.

  • Xlrd: Through this library file we were able to read all details from excel sheet and simultaneously connect different FTP servers.

Finally, we were able to download and upload files to different FTP server at a time.

Then, we were trying to perform some basic file zip/unzip, delete, log operations in FTP and local server. This was possible using shutil, zipfile, log and datetime library files. Some of the basic operational details of these library files are:

  1. zipfile — Used to archive file
  2. shutil — Used to delete file
  3. datetime — Used to rename files name with date and time.
  4. log — Used to create log file.

Automation Part:

Using the above library files and code snippet we were able to achieve this process. The next step is to automate this entire process. So, we used windows task manager to automate the ftp process by scheduling it at time intervals.

Summary :

At last, we were able to complete tasks like transfer, delete, archive and rename the files on a FTP Server using python. From my experience Python is a very flexible and user-friendly language. Using simple library files I was able to complete the above tasks quickly. But some errors like space error was little annoying and took us some time to figure it out. But with the help of my team I was able to accomplish this entire task successfully.


Keerthi Veerappan

An INFJ personality wielding brevity in speech and writing. Marketer @ Zucisystems.