栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

实验6 推送备份文件到FTP服务器

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实验6 推送备份文件到FTP服务器

模拟器里的IP 已经变动

import paramiko
import time
username = 'python'
password = '123asd'
iplist =['192.168.1.9', '192.168.1.10', '192.168.1.11']
for ip in iplist:
    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh_client.connect(hostname=ip, username=username, password=password, look_for_keys=False)
    print('=-=-=-=-=-=-=-=-=-=-=-=-=-=')
    print('已经成功登陆交换机 ' + ip)
    command = ssh_client.invoke_shell()
    command.send('ftp 192.168.1.8n')
    time.sleep(0.5)
    command.send('rootn')
    time.sleep(0.5)
    command.send('Lxf940709.n')
    time.sleep(0.5)
    command.send('binn')
    command.send('put vrpcfg.zip '+ip +'_vrpcfg.zip'+'n')
    time.sleep(0.5)
    command.send('quitn')
    time.sleep(0.5)
    output = command.recv(65535).decode('GB2312')
    print(output)
ssh_client.close()
C:Users82127.condaenvspythonProjectpython.exe E:/log/python/pythonProject/Demo06.py
=-=-=-=-=-=-=-=-=-=-=-=-=-=
已经成功登陆交换机 192.168.1.9

Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 1.
      The current login time is 2022-06-01 23:34:42.
ftp 192.168.1.8
Trying 192.168.1.8 ...
Press CTRL+K to abort
Connected to 192.168.1.8.
220 (vsFTPd 3.0.3)
User(192.168.1.8:(none)):root
331 Please specify the password.
Enter password:
230 Login successful.

[ftp]bin
200 Switching to Binary mode.

[ftp]put vrpcfg.zip 192.168.1.9_vrpcfg.zip
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
FTP: 602 byte(s) sent in 0.170 second(s) 3.54Kbyte(s)/sec.

[ftp]quit

221 Goodbye.


=-=-=-=-=-=-=-=-=-=-=-=-=-=
已经成功登陆交换机 192.168.1.10

Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 1.
      The current login time is 2022-06-01 23:34:45.
ftp 192.168.1.8
Trying 192.168.1.8 ...
Press CTRL+K to abort
Connected to 192.168.1.8.
220 (vsFTPd 3.0.3)
User(192.168.1.8:(none)):root
331 Please specify the password.
Enter password:
230 Login successful.

[ftp]bin
200 Switching to Binary mode.

[ftp]put vrpcfg.zip 192.168.1.10_vrpcfg.zip
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
FTP: 603 byte(s) sent in 0.160 second(s) 3.76Kbyte(s)/sec.

[ftp]quit

221 Goodbye.


=-=-=-=-=-=-=-=-=-=-=-=-=-=
已经成功登陆交换机 192.168.1.11

Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 1.
      The current login time is 2022-06-01 23:34:48.
ftp 192.168.1.8
Trying 192.168.1.8 ...
Press CTRL+K to abort
Connected to 192.168.1.8.
220 (vsFTPd 3.0.3)
User(192.168.1.8:(none)):root
331 Please specify the password.
Enter password:
230 Login successful.

[ftp]bin
200 Switching to Binary mode.

[ftp]put vrpcfg.zip 192.168.1.11_vrpcfg.zip
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
FTP: 603 byte(s) sent in 0.190 second(s) 3.17Kbyte(s)/sec.

[ftp]quit

221 Goodbye.



进程已结束,退出代码0

[root@testhost ~]# ll
total 20
-rw-r--r--  1 root root  603 Jun  2 07:34 192.168.1.10_vrpcfg.zip
-rw-r--r--  1 root root  603 Jun  2 07:34 192.168.1.11_vrpcfg.zip
-rw-r--r--  1 root root  602 Jun  2 07:34 192.168.1.9_vrpcfg.zip

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/942706.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号