Home > Mobile >  how to send these files that are inside the "qnttest.txt" for each ftp, example: file1 to
how to send these files that are inside the "qnttest.txt" for each ftp, example: file1 to

Time:11-13

...
file = 'ip.txt'
    arquivo = open(file, "r").readlines()
    for linha in arquivo:
        linha = linha.strip()
        print(linha   " Sucesso")
        ssh_client =paramiko.SSHClient()
        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh_client.connect(hostname=linha,username='root',password='Server123@')
        ftp_client = ssh_client.open_sftp ()
    
        file = 'qnttestl.txt' #diretorios
        arquivo = list(open(file, "r").readlines())
        for linha in arquivo:
            linha = linha.strip() 
            print(linha)
            #fila = arquivo
    
            file = 'qnt.txt'
            txts =  list(open(file, "r").readlines())
            for linha in txts: 
                        v2 = open('ip.txt', "r").readlines()
                        for linha in v2:
                            linha = len(linha.strip())
                            ftp_client.put (linha,  '/root/test.txt')     
    ## this line that sends the file that is in "qnttest.txt" to "ftp", but it is sending all files from "qnttest.txt to a "ftp" only, I want it to send a file (one line of " qnttest.txt") for each "ftp" in "ip.txt", each line of "qnttest.txt" is a file ## 
    
    
    ## essa linha que envia o arquivo que ta no "qnttest.txt" para o "ftp", só que ela ta enviando todos arquivos do "qnttest.txt pra um "ftp" só, quero q ela envie um arquivo(uma linha do "qnttest.txt") para cada "ftp" que ta no "ip.txt", cada linha do "qnttest.txt" é um arquivo ##
    
      
                            ftp_client.put ('test.html', '/root/test.html')
                            ftp_client.put ('test.pl', '/root/test.pl')
                            ftp_client.put ('test.txt', '/root/test.txt')
...

CodePudding user response:

If you want to send one file to one ftp then you should first read all data from both files and later use zip() to create pairs (ftp1, file1), (ftp2, file2), etc.

all_filenames = open('qnttestl.txt').read().split("\n")

all_ftps = open('ip.txt').read().split("\n")


for ftp, filename in zip(all_ftps, all_filename):
    print('sendig', filname, 'to ftp', ftp)
    # ... code to send file ...
  • Related