Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
master_project_JLU2018/bin/3.1_create_gtf/Modules/Ensembl/FTPHandling/FTPEntry.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 lines (33 sloc)
1.31 KB
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
import ftplib | |
class FTPEntry: | |
""" | |
Class to determine if a ftp-path is file or directory. | |
Assigns every filename a parameter ('d' = directory or 'f' = file) | |
@author: Sebastian Beyvers | |
@contact: sebastian.beyvers@med.uni-giessen.de | |
""" | |
def __init__(self, filename, ftpobj, startingdir=None): | |
# Constructor | |
# input_parameter: filename = the files/directorys name | |
# ftpobj = Current Instance of FTPLib from URLRetrieve | |
# startingdir = optional parameter for ftp starting directory (to reduce browsing in ftp) | |
self.filename = filename | |
if startingdir is None: | |
startingdir = ftpobj.pwd() | |
# Try if "filename" is directory | |
try: | |
ftpobj.cwd(filename) | |
self.filetype = 'd' | |
ftpobj.cwd(startingdir) | |
# If error_perm occurs filename is file not directory | |
except ftplib.error_perm: | |
self.filetype = 'f' | |
def gettype(self): | |
# Getter method for filetype | |
return self.filetype | |
def getfilename(self): | |
# Getter method for filenname | |
return self.filename | |
def __repr__(self): | |
# Change the represenation scheme for FTPEntry object. | |
return self.filename, self.filetype |