简体   繁体   English

如何为每个ftp发送“qnttest.txt”中的这些文件,例如:file1到ftp1,file2到ftp2

[英]how to send these files that are inside the "qnttest.txt" for each ftp, example: file1 to ftp1, file2 to ftp2

...
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')
...

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.如果你想将一个文件发送到一个 ftp,那么你应该首先从两个文件中读取所有数据,然后使用zip()创建对(ftp1, file1) , (ftp2, file2)等。

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 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM