Skip to content
Permalink
4f40b11ca2
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
54 lines (33 sloc) 1.31 KB
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