Beispiel #1
0
def runMe():
    global finalString;
    global ftp;
    
    finalString = '['
    ftp=FTP('ftp.ncnr.nist.gov')
    ftp.login()
    ftp.cwd('pub')
    
    root = FTPfile(id_counter,ftp.pwd(),[],False)
    children = getChildren(root.path)

    ftp.quit()

    if children:
        root.setChildren(children)
    else:
        root.isLeaf() #isLeaf sets to leaf
    #print root
    #for i in root.children:
    #	print i.id, i
    #print root.children
    #print ftp.nlst()
    #setupTree(root)
    toJson(root)
    finalString += ']'
    #write=open('ftpDir.txt','w')
    #write.write(finalString)
    #write.close()
    #print finalString
    #return finalString
    return ast.literal_eval(finalString)
Beispiel #2
0
def runFTP(address, directory,  username='', password=''):
    """
    FTP into a given ``address`` and change into the directory ``directory``.
    This will provide the set of files and directories within ``directory``.
    """
    global finalString;
    global ftp;
    
    finalString = '['
    ftp = FTP(address)
    ftp.login(user=username, passwd=password)
    ftp.cwd(directory)
    
    root = FTPfile(id_counter, ftp.pwd(), [], False)
    
    children = getChildren(root.path)
    if children:
        root.setChildren(children)
    else:
        root.isLeaf() #sets root as a leaf
    
    ftp.quit()
    toJson(root, isexpanded=True)
    finalString += ']'
    return ast.literal_eval(finalString)
Beispiel #3
0
def getChildren(directory):
    global id_counter

    try:
        ftp.cwd(directory)
    except Exception:
        pass

    if directory == '/':
        #if the directory is the root, set it to nothing so two '/' are not appended
        directory = ''

    childList = []
    data = []
    ftp.dir(data.append)
    for i in data:
        name = i.split()[-1]
        if i.lower().startswith('d'):
            childList.append(
                FTPfile(id_counter, directory + '/' + name, [], False))
        else:
            childList.append(
                FTPfile(id_counter, directory + '/' + name, [], True))
    '''for i in ftp.nlst():
        id_counter+=1
        childList.append(FTPfile(id_counter, directory+'/'+i,[], False))
    '''
    return childList
Beispiel #4
0
def runMe():
    global finalString
    global ftp

    finalString = '['
    ftp = FTP('ftp.ncnr.nist.gov')
    ftp.login()
    ftp.cwd('pub')

    root = FTPfile(id_counter, ftp.pwd(), [], False)
    children = getChildren(root.path)

    ftp.quit()

    if children:
        root.setChildren(children)
    else:
        root.isLeaf()  #isLeaf sets to leaf
    #print root
    #for i in root.children:
    #	print i.id, i
    #print root.children
    #print ftp.nlst()
    #setupTree(root)
    toJson(root)
    finalString += ']'
    #write=open('ftpDir.txt','w')
    #write.write(finalString)
    #write.close()
    #print finalString
    #return finalString
    return ast.literal_eval(finalString)
Beispiel #5
0
def runFTP(address, directory, username='', password=''):
    """
    FTP into a given ``address`` and change into the directory ``directory``.
    This will provide the set of files and directories within ``directory``.
    """
    global finalString
    global ftp

    finalString = '['
    ftp = FTP(address)
    ftp.login(user=username, passwd=password)
    ftp.cwd(directory)

    root = FTPfile(id_counter, ftp.pwd(), [], False)

    children = getChildren(root.path)
    if children:
        root.setChildren(children)
    else:
        root.isLeaf()  #sets root as a leaf

    ftp.quit()
    toJson(root, isexpanded=True)
    finalString += ']'
    return ast.literal_eval(finalString)
Beispiel #6
0
def runFullRecursionFTP(address):
    """
    FTP into a given ``address`` and gets the full directory structure
    NOTE: for larger trees, setupTree will usually time-out.
    """
    global finalString
    global ftp

    finalString = '['
    ftp = FTP(address)
    ftp.login()

    root = FTPfile(id_counter, ftp.pwd(), [], False)

    setupTree(root)  #full depth-first recursion takes too long

    ftp.quit()
    toJson(root)
    finalString += ']'
    return ast.literal_eval(finalString)