Beispiel #1
0
def get_file_names_ftp(ftp_root, coll_name, force_db_update=False):
    # coll = db[coll_name]

    ftp = FTPHost.connect(p.private_ftp,
                          user=p.ftp_user,
                          password=p.ftp_password)
    for (dirname, subdirs, files) in ftp.walk(ftp_root):
        for file in files:
            logging.debug("File: %s" % file)
            file_path = (str(dirname) + '/' + file)
            corrected_filepath = correct(
                ekezettelenit(file_path).replace("//", "/"))
            item = {
                'ftp_path': corrected_filepath,
                'original_ftp_path': file_path,
                'ftp_root': ftp_root,
                'updated_at': datetime.now()
            }
            existing = mongo.find_by_ftp_path(corrected_filepath,
                                              coll_name=coll_name)
            if existing:
                logging.info("%s already exists!" % file)
                if force_db_update:
                    logging.debug("updating Mongo")
                    mongo.update_item(coll_name=coll_name,
                                      item=existing,
                                      properties=item)
                    logging.debug("Added: %s" % item)
            else:
                logging.debug("inserting into Mongo")
                mongo.insert_one(item, coll_name=coll_name)
                logging.debug("Added: %s" % item)
        logging.debug("Subdirs: %s" % subdirs)
        logging.info("%s done." % dirname)
    return
    def try_to_connect(self):
        try:
            self.ftp = FTPHost.connect(DWD_SERVER, user = DWD_USERNAME, password = DWD_PASSWORD, timeout = 20)


        except IOError as e:
            #raise ValueError(f'I/O error({e.errno}): {e.strerror}')
           return Response400(code=e.errno, message=e.strerror)
Beispiel #3
0
def _get_ftp_data(data):
    outputs = []
    conn = FTPHost.connect(
        data["address"], user=data["user"], password=data["password"]
    )
    for (dirname, subdirs, files) in conn.walk(data.get("path", "/")):
        outputs.append((dirname, files))
    conn.try_quit()
    return outputs
Beispiel #4
0
def _get_ftp_data(data):
    outputs = []
    conn = FTPHost.connect(data["address"],
                           user=data["user"],
                           password=data["password"])
    for (dirname, subdirs, files) in conn.walk(data.get("path", "/")):
        outputs.append((dirname, files))
    conn.try_quit()
    return outputs
Beispiel #5
0
	def GetFiles(self, directory):
		
		a_host = FTPHost.connect(self.addr,user=self.user,password=self.passwd)
		alld = {'': {}}
		print self.folder
		x=[]
		self.ftp.dir('-d','*/',lambda L:x.append(L.split()[-1]))
		print x
#		for (dirname, subdirs, files) in a_host.walk(self.folder):
#			d = alld
#			dirname = dirname[len(self.folder):]
#			print dirname
#			for subd in dirname.split('/'):
#				based = d
#				d = d[subd]
#			if subdirs:
#				for dn in subdirs:
#					d[dn] = {}
#			else:
#				based[subd] = files
		alld['':x]
		return alld['']
Beispiel #6
0
 def conn(self):
     return FTPHost.connect(GEO_HOST,
                            user="******",
                            password="******",
                            timeout=SOCKET_TIMEOUT)
Beispiel #7
0
 def conn(self):
     return FTPHost.connect(SERIES_MATRIX_URL.netloc,
                            user="******",
                            password="******",
                            timeout=SOCKET_TIMEOUT)
Beispiel #8
0
import ftplib
from ftptool import FTPHost

ftp = ftplib.FTP("garner.ucsd.edu", 'anonymous', "*****@*****.**")
a_host = FTPHost(ftp)
a_host.mirror_to_local(
    '/pub/solutions/gipsy/trop',
    '/home/shlomi/Desktop/DATA/Work_Files/PW_yuval/garner/trop')
Beispiel #9
0
import ftptool
from ftptool import FTPHost
#
passwd = input("podawaj: ")
ahost = FTPHost.connect("ftp.pl", user="******", password=passwd)
ahost.current_directory = ""
#
for (dirname, subdirs, files) in ahost.walk("."):
    print (dirname, "has file(s)", ", ".join(files))
Beispiel #10
0
# -*- coding: utf-8 -*-

from __future__ import print_function
import os
from ftptool import FTPHost

# ftp://ftp.gnu.org/
a_host = FTPHost.connect("ftp://ftp.gnu.org/",
                         user="******",
                         password="",
                         timeout=1000)

a_host.current_directory = "/"

for (dirname, subdirs, files) in a_host.walk("/"):
    for subdir in subdirs:
        if subdir.startswith("other_"):
            subdirs.remove(subdir)
    print(dirname, "has file(s)", ", ".join(files))


# print tree
def FtpWalker(dirname, prefix=""):
    a_host.current_directory = dirname
    (subdirs, files) = a_host.listdir(dirname)
    print(prefix, dirname, ": ", ", ".join(files), sep="")
    for subdir in subdirs:
        FtpWalker(dirname + "/" + subdir, prefix=prefix + "\t")


FtpWalker("/")