Connect with us

Bioinformatics Programming

How to download files from an FTP server using Python?

Published

on

How to download files from an FTP server using Python?

In this article, we provide a simple Python script to download files from an FTP server using Python.

Write the FTP address and your username and password in the place specified below. Save this file in Python format (for example, download.py) and run it as:

$ python3 download.py



#!/usr/bin/env python3

import fnmatch
from ftplib import FTP

ftp = FTP('ftp address')

#if no username and password is required.
ftp.login()

#if username and password is required.         
ftp.login('your-username','your-password')    

# if you have to change directory on FTP server.
ftp.cwd('/path/to/dir/')

# Get all files
files = ftp.nlst()

# Download files
for file in files:
    if fnmatch.fnmatch(file, '*.tar.gz'):   #To download specific files.
        print("Downloading..." + file)

        try:
            ftp.retrbinary("RETR " + file ,open("/path/to/dir/on/your/local/system/" + file, 'wb').write)

        except EOFError:    # To avoid EOF errors.
            pass

ftp.close()


Dr. Muniba is a Bioinformatician based in New Delhi, India. She has completed her PhD in Bioinformatics from South China University of Technology, Guangzhou, China. She has cutting edge knowledge of bioinformatics tools, algorithms, and drug designing. When she is not reading she is found enjoying with the family. Know more about Muniba

Bioinformatics Programming

How to make swarm boxplot?

Published

on

How to make swarm boxplot?

With the new year, we are going to start with a very simple yet complicated topic (for beginners) in bioinformatics. In this tutorial, we provide a simple code to plot swarm boxplot using matplotlib and seaborn. (more…)

Continue Reading

Bioinformatics Programming

How to obtain ligand structures in PDB format from PDB ligand IDs?

Published

on

How to obtain ligand structures in PDB format from PDB ligand IDs?

Previously, we provided a similar script to download ligand SMILES from PDB ligand IDs. In this article, we are downloading PDB ligand structures from their corresponding IDs. (more…)

Continue Reading

Bioinformatics Programming

How to obtain SMILES of ligands using PDB ligand IDs?

Published

on

How to obtain SMILES of ligands using PDB ligand IDs?

Fetching SMILE strings for a given number of SDF files of chemical compounds is not such a trivial task. We can quickly obtain them using RDKit or OpenBabel. But what if you don’t have SDF files of ligands in the first place? All you have is Ligand IDs from PDB. If they are a few then you can think of downloading SDF files manually but still, it seems time-consuming, especially when you have multiple compounds to work with. Therefore, we provide a Python script that will read all Ligand IDs and fetch their SDF files, and will finally convert them into SMILE strings. (more…)

Continue Reading

LATEST ISSUE

ADVERT