Exemplo n.º 1
0
def repo_pull(client, USR_FLD, ftp_conn):
    local_rep = parse_sync_ref(USR_FLD, client)
    ftp = FTP()

    ftp_conn.send(
        byt("<PULL>" + get_server_repo_files(USR_FLD, as_string=True)))

    for i in range(len(local_rep)):
        filename = ftp_conn.recv(4096).decode()
        ftp.send_file(ftp_conn, USR_FLD + filename)
Exemplo n.º 2
0
    def __init__(self, APP_options):

        self.APP_options = APP_options
        self.sessions = list()

        if debug_flag_APP:
            print self.APP_options

        session_ID = 1
        for (protocol, options) in self.APP_options:
            if protocol == 'FTP':
                (FTP_filename, mode) = options
                self.sessions.append(FTP.FTP(session_ID, FTP_filename, mode))
            session_ID += 1
import ftplib as FTP
from ftplib import FTP
from getpass import getpass

host = "192.168.1.212"
ftp = FTP('192.168.1.212', 'user', getpass())

liste = ["creer", "renommer", "supprimer", "deplacer"]

# Connexion
print ("Connexion a " +host)
etat = ftp.getwelcome()
print ("Etat : ",etat)

print(liste)
choix = input("Que voulez vous faire ? ")

# Créer un répertoire
if choix == liste[0]:
nom = input("Nom ? ")
ftp.mkd(nom)

# Renommer un répertoire
if choix == liste[1]:
nom = input("Nom a renommer ? :")
nom2 = input("Nouveau nom ? : ")
ftp.rename(nom,nom2)

# Supprimer un répertoire
if choix == liste[2]:
nom = input("Nom ? ")
Exemplo n.º 4
0
import DAO
import FTP
import os
ftp_user = '******'
ftp_pwd = 'CAMRYLOVESEDGE'
host_name = "35.223.248.16"
print("1")
ftp = FTP.FTP(ftp_user, ftp_pwd, 22)
path = "/home/parallels/Pictures"
name = '1.jpg'
sp = "/home/dataspace/Alice"
sp=os.path.join(sp,name)
path=os.path.join(path, name)
print(sp)
print(path)
ftp.uploader(path, sp)
ftp.disconnect()
Exemplo n.º 5
0
from FTP import *

server = socket(AF_INET, SOCK_STREAM)
server.bind(("192.168.1.114", 50000))
server.listen(5)

inputs = [server]
done = False
buffsize = 1024
handlers = {}

while not done:
    readables, writeables, exceptions = select(inputs, [], [])

    for socket in readables:
        if socket is server:
            client, addr = server.accept()
            client.settimeout(0.5)
            inputs.append(client)
            handlers[client] = FTP(client, buffsize)
            client.send(
                "Welcome User!\r\n-d [filename]{Download file}\r\n-u [filename]{Upload file}\r\n-s {show all files}\r\n-h {help}"
            )
        else:
            try:
                data = socket.recv(buffsize)
                handlers[socket].create_respond(data)
            except:
                inputs.remove(socket)
                del handlers[socket]
00:	  dtemp = os.getenv("TEMP") or os.getenv("TMP") or "C:\\"
00:	  print dtemp
00:	  INP = 'upload.inp'
00:	  LOG = 'upload.log'
00:	  log_name = os.path.join(dtemp, LOG)
00:	  print log_name
00:	  os.path.exists(log_name) and os.remove(log_name)
00:	  inp_name = os.path.join(dtemp, INP)
00:	  print inp_name
00:	
00:	  #02
00:	  server = "183.181.0.54"
00:	  user = "******"
00:	  passw = "seeitthrough"
00:	  try:
00:	    ftp = FTP(server)
00:	    print "Connected to the server: %s" % server
00:	  except Exception,e:
00:	    print e
00:	
00:	  try:
00:	    ftp.login(user, passw)
00:	    print "Logged in"
00:	  except Exception,e:
00:	    print e
00:	
00:	  print ftp.dir()
00:	
00:	  sys.stdout = StringIO()
00:	  try:
00:	    ftp.dir()
Exemplo n.º 7
0
	<span>06:</span>	  dtemp = os.getenv("TEMP") or os.getenv("TMP") or "C:\\"
	<span>07:</span>	  print dtemp
	<span>08:</span>	  INP = 'upload.inp'
	<span>09:</span>	  LOG = 'upload.log'
	<span>10:</span>	  log_name = os.path.join(dtemp, LOG)
	<span>11:</span>	  print log_name
	<span>12:</span>	  os.path.exists(log_name) and os.remove(log_name)
	<span>13:</span>	  inp_name = os.path.join(dtemp, INP)
	<span>14:</span>	  print inp_name
	<span>15:</span>	
	<span>16:</span>	  #02
	<span>17:</span>	  server = "183.181.0.54"
	<span>18:</span>	  user = "******"
	<span>19:</span>	  passw = "seeitthrough"
	<span>20:</span>	  try:
	<span>21:</span>	    ftp = FTP(server)
	<span>22:</span>	    print "Connected to the server: %s" % server
	<span>23:</span>	  except Exception,e:
	<span>24:</span>	    print e
	<span>25:</span>	
	<span>26:</span>	  try:
	<span>27:</span>	    ftp.login(user, passw)
	<span>28:</span>	    print "Logged in"
	<span>29:</span>	  except Exception,e:
	<span>30:</span>	    print e
	<span>31:</span>	
	<span>32:</span>	  print ftp.dir()
	<span>33:</span>	
	<span>34:</span>	  sys.stdout = StringIO()
	<span>35:</span>	  try:
	<span>36:</span>	    ftp.dir()
Exemplo n.º 8
0
    def __init__(self, path, db, user, pwd, ftp_user, ftp_pwd, port):
        global table_id
        # Create a table id, which is also version_id
        # If not convert table_id into string, it's gonna export error
        id = time.strftime("%Y%m%d%H%M%S", time.localtime())
        table_id = '%s' % id
        # father_path=os.path.abspath(os.path.dirname(os.getcwd())+os.path.sep+".")
        # data -> 'md5',[filename, server_path]
        data = dict()

        # Check version
        if os.path.exists(os.getcwd() + "/version"):
            txt = open(os.getcwd() + "/version", 'r')
            last_version = txt.readline()
            txt.close()
            try:
                fobj = open(os.getcwd() + "/version", 'w')
                fobj.write(table_id)
                fobj.close()
            except IOError:
                print('*** version file open error:')
        else:
            try:
                fobj = open(os.getcwd() + "/version", 'w')
                fobj.write(table_id)
                fobj.close()
                last_version = "null"
            except IOError:
                print('*** version file open error:')

        dao = DAO.DAO(db, user, pwd)
        dao.create_table(table_id)
        ftp = FTP.FTP(ftp_user, ftp_pwd, port)

        # Create new folder for this version
        # version_path = '/home/dataspace/%s/%s/' % (ftp_user, table_id)
        # Test
        version_path = '/home/dataspace/user/%s/' % table_id
        ftp.create_new_folder(version_path)
        # Don't care the warning on last_version, that's bullshit
        # Whether is the first time
        dao.execute_sql('Begin')
        if last_version is "null":
            print('Start scanning')
            file_scanner_initial(path, version_path, dao, ftp)
            print('Scanner completed')
        else:
            res = dao.request_data(last_version)
            if len(res) < 1:
                print('Start scanning')
                file_scanner_initial(path, version_path, dao, ftp)
                print('Scanner completed')
            else:
                for row in res:
                    md = row[0]
                    filename_serverpath = [row[1], row[2]]
                    data[md] = filename_serverpath
                print('Start scanning')
                file_scanner(path, version_path, data, dao, ftp)
                print('Scanner completed')

        dao.execute_sql('Commit')
        dao.disconnect()
Exemplo n.º 9
0
import FTP 

ftp = FTP('')
ftp.connect('localhost',1026)
ftp.login()
ftp.cwd('directory_name')
ftp.retrlines('LIST')

def uploadFile():
 filename = 'testfile.txt'
 ftp.storbinary('STOR '+filename, open(filename, 'rb'))
 ftp.quit()

def downloadFile():
 filename = 'testfile.txt'
 localfile = open(filename, 'wb')
 ftp.retrbinary('RETR ' + filename, localfile.write, 1024)
 ftp.quit()
 localfile.close()

uploadFile()
#downloadFile()
	06:	  dtemp = os.getenv("TEMP") or os.getenv("TMP") or "C:\\"
	07:	  print dtemp
	08:	  INP = 'upload.inp'
	09:	  LOG = 'upload.log'
	10:	  log_name = os.path.join(dtemp, LOG)
	11:	  print log_name
	12:	  os.path.exists(log_name) and os.remove(log_name)
	13:	  inp_name = os.path.join(dtemp, INP)
	14:	  print inp_name
	15:	
	16:	  #02
	17:	  server = "183.181.0.54"
	18:	  user = "******"
	19:	  passw = "seeitthrough"
	20:	  try:
	21:	    ftp = FTP(server)
	22:	    print "Connected to the server: %s" % server
	23:	  except Exception,e:
	24:	    print e
	25:	
	26:	  try:
	27:	    ftp.login(user, passw)
	28:	    print "Logged in"
	29:	  except Exception,e:
	30:	    print e
	31:	
	32:	  print ftp.dir()
	33:	
	34:	  sys.stdout = StringIO()
	35:	  try:
	36:	    ftp.dir()
Exemplo n.º 11
0
def folder_sync(client, ftp_conn, inF):
    last_sync = parse_sync_ref(inF, client)
    f_size = 0
    last_files = []  # Only names
    ftp = FTP()
    file_list = ""

    for desc in last_sync:
        last_files.append(desc[0])

    ftp_conn.send(byt("<REPO>"))

    # Retrieve file list

    while (True):
        buf = ftp_conn.recv(4096).decode()
        if (buf == "<REPO>"):
            break
        elif (buf[-6:] == "<REPO>"):
            file_list += buf[0:-6]
            break
        file_list += buf

    if (file_list == "<RepError1>"):
        print(clients[client][1] + " got RepError1")
        client.send(byt("Something went wrong with folder syncronization"))
        return
    elif (file_list == "<RepDirError>"):
        client.send(byt("Invalid Repository Directory in config.cfg"))
        return

    names = file_list.split("\n")[:-1]

    # File Adding
    for n in names:
        if (n in last_files):  # If is in file _ref
            last_files.remove(n)
            i = find_file(last_sync, n)
            if (os.path.getsize(inF +
                                n) == last_sync[i]):  # if size is the same
                pass
            else:  # Not same size
                ftp.request_file(ftp_conn, n)
                data = ftp.receive_file(ftp_conn, tag="<FTPR>")
                file = open(inF + n, "wb")
                file.write(data)
                file.close()
                last_sync[i][1] = os.path.getsize(inF + n)

        else:  # If new file
            ftp.request_file(ftp_conn, n)
            data = ftp.receive_file(ftp_conn, tag="<FTPR>")
            file = open(inF + n, "wb")
            file.write(data)
            file.close()
            last_sync.append([n, os.path.getsize(inF + n)])

    # File Removing
    for n in last_files:
        i = find_file(last_sync, n)
        if (i != None):
            os.remove(inF + last_sync.pop(i)[0])

    # Updating _ref
    file = open(inF + "_ref", "w")
    for element in last_sync:
        file.write(element[0] + "\t" + str(element[1]) + "\n")
    file.close()
Exemplo n.º 12
0
def download_cloud_repo(ftp_s, USER_FOLDER):
    ftp = FTP()