Created
May 26, 2017 23:08
-
-
Save indraniel/02b16a2c3d0ff6518e0e025483791c59 to your computer and use it in GitHub Desktop.
Python example to download files from an anonymous FTP server (example case from 1000 Genomes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import ftplib, datetime, sys | |
# ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.chr14.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz | |
def log(msg): | |
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %T") | |
print('[-- {} --] {}'.format(timestamp, msg), file=sys.stderr) | |
server = 'ftp.1000genomes.ebi.ac.uk' | |
directory = 'vol1/ftp/release/20130502' | |
vcf = 'ALL.chr14.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz.tbi' | |
log("connecting to server") | |
ftp = ftplib.FTP(server) | |
ftp.login() | |
log("changing to directory: {}".format(directory)) | |
ftp.cwd(directory) | |
ftp.retrlines('LIST') | |
log("starting to download: {}".format(vcf)) | |
ftp.retrbinary("RETR {}".format(vcf), open(vcf, 'wb').write) | |
log("finished download") | |
ftp.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment