ftplib模块编写简单的ftp服务
from ftplib import *
import os,readline
import sys
class MyFtp:
ftp = FTP() #建立一个ftp对象的链接
def __init__(self, host, port=''): #构造函数初始化
self.ftp.connect(host=host,timeout=100) #连接ftp服务器
def Login(self, user, passwd): #登录函数
self.ftp.login(user=user, passwd=passwd )
print (self.ftp.welcome) #登陆成功后ftp显示欢迎信息 def DownLoadFile(self, LocalFilePath, RemoteFilePath):
file = open(LocalFilePath, 'wb')
self.ftp.retrbinary( "RETR %s" %( RemoteFilePath ), file.write ) #下载文件到本地
file.close()
return True def DownLoadFileTree(self, LocalFileDir, RemoteFileDir):
if os.path.isdir( LocalfileDir ) == False: #如果传入本地的不是目录
os.makedirs(LocalFileDir) #就在本地新建该目录
self.ftp.cwd(RemoteFileDir) #切换到远程目录
RemoteFiles = self.ftp.nlst() #把远程目录里的所有文件都传给 RemoteFiles变量
for file in RemoteFiles:
Local = os.path.join(LocalFilesDir, file )
chang = os.path.join(RemoteDir,file )
if self.IsDir(chang):
self.DownLoadFileTree(Local, chang)
else:
self.DownLoadFile( Local, chang)
self.ftp.cwd( ".." ) def IsDir(self, path):
if os.path.isdir(path) == True:
self.juge = True
else:
self.juge = False
return self.juge def UpLoadFileTree(self, LocalFileDir, RemoteFileDir):
if os.path.isdir(LocalFileDir) == False:
print( 'wrong !Please Input Dir')
if os.path.isdir(RemoteFileDir) == False:
os.makedirs(RemoteFileDir)
LocalFiles = os.listdir(LocalFileDir)
self.ftp.cwd(RemoteFileDir)
for Local in LocalFiles:
src = os.path.join( LocalFileDir, Local)
chang = os.path.join(RemoteFileDir,Local)
if os.path.isdir(src):
self.UpLoadFileTree(src,chang)
else:
self.UpLoadFile(src,chang)
self.ftp.cwd( ".." ) def UpLoadFile(self, LocalFilePath, RemoteFilePath):
if os.path.isfile( LocalFilePath ) == False:
return False
file = open(LocalFile, "rb")
self.ftp.storbinary('STOR %s'%RemoteFile, file, 4096)
file.close() ftp = myFtp('192.168.19.153') #实例化 def Login():
ftp.Login('root','root')
def Update():
print('\033[34mUping.....\033[m')
ftp.UpLoadFileTree('main', "/xxx" )
print('Done')
def DownLoad():
print('\033[34mDowning.....\033[m')
ftp.DownLoadFileTree('localDir','remoteDir')
print ('Done')
def Close():
self.ftp.quit() def Menu():
print ("""\033[;32mWelcome \033[0m\n""")
print ("\t(1) Login")
print ("\t(2) Update")
print ("\t(3) DownLoad")
print ("\t(4) close")
while True:
choices = raw_input('\033[32mChoice>>\033[m').strip()
if len(choices) == 0:continue
if choices == '':Login()
elif choices == '':Update()
elif choices == '':DownLoad()
elif choices == '':close() Menu() http://www.cnblogs.com/zhuweiblog/p/5154752.html
ftplib模块编写简单的ftp服务的更多相关文章
- 1 学习wcf 编写简单的WCF服务流程 并发布在IIS上
学习笔记 学习大佬的博客 https://www.cnblogs.com/iamlilinfeng/archive/2012/09/25/2700049.html 写一遍加深印象 图片看不清楚的 可 ...
- linux服务基础之ftp服务
ftp是一种文件传输协议,我们以redhat6.9为服务器系统,来介绍一下ftp服务器,这里我们先介绍一下ftp协议工作的原理 ftp协议可以在不同类型的计算机之间传输文件,工作流程大致为 1:客户机 ...
- 安装Linux Deploy和Termux之后,再安装ftp服务软件都是多余的!
之前以为Debian 9 running via Linux Deploy或者Termux在安卓系统部署之后,一定要安装vsftpd或者pure-ftpd这些专门的ftp服务器软件,才能提供ftp服务 ...
- SELECTORS模块实现并发简单版FTP
环境:windows, python 3.5功能:使用SELECTORS模块实现并发简单版FTP允许多用户并发上传下载文件 结构:ftp_client ---| bin ---| start_clie ...
- python3 ftplib模块连接FTP
from ftplib import FTP_TLS import os import re class MyFtp(FTP_TLS): """继承FTP类"& ...
- python模块之sys和subprocess以及编写简单的主机扫描脚本
python模块之sys和subprocess以及编写简单的主机扫描脚本 1.sys模块 sys.exit(n) 作用:执行到主程序末尾,解释器自动退出,但是如果需要中途退出程序,可以调用sys.e ...
- python使用ftplib模块实现FTP文件的上传下载
python已经默认安装了ftplib模块,用其中的FTP类可以实现FTP文件的上传下载 FTP文件上传下载 # coding:utf8 from ftplib import FTP def uplo ...
- node http模块搭建简单的服务和客户端
node-http Node.js提供了http模块,用于搭建HTTP服务端和客户端. 创建Web服务器 server.js /** * node-http 服务端 */ let http = req ...
- Centos 7 部署FTP服务简单版
第三方教程推荐与参考: http://blog.csdn.net/somehow1002/article/details/70232791 先安装成功了,有信心了.再进一步扩展配置. 1.安装vsft ...
随机推荐
- jmeter返回报文乱码问题
返回的报文中存在乱码如下: 1.先改脚本里面的 content encoding为utf-8 然后response为utf-8 如果以上还是不可以,那就改配置文件jmeter.properties,里 ...
- caffe配置
2016年最开心的事哈哈哈. 基本参照它. http://www.linuxdiyf.com/linux/12708.html 有时间在稍微写点. linux下:(装上GPU之后,在bois貌似禁止了 ...
- kubeadm搭建kubernetes集群之一:构建标准化镜像
使用docker可以批量管理多个容器,但都是在同一台电脑内进行的,这在实际生产环境中是不够用的,如何突破单机的限制?让多个电脑上的容器可以像单机上的docker-compose.yml管理的那样方便呢 ...
- 21天学通C++_Day5
昨天停更了一天,真是羞羞啊,不过还是干了很多有意义的事的! 首先,昨天下午的时候,去参加了学校的春招!第一次参加招聘会,怕自己答不上面试官的问题,很是紧张! 和同学约的一点,结果到了发现还没开始,只能 ...
- Jmeter图形结果
样本数目:总共发送到服务器的请求数 最新样本:代表时间的数字,是服务器响应最后一个请求的时间 吞吐量:服务器每分钟处理的请求数.是指在没有帧丢失的情况下,设备能够接受的最大速率. 平均值:总运行时间除 ...
- 20179223《Linux内核原理与分析》第四周学习笔记
补交第三周作业 完成一个简单的时间片轮转多道程序内核 1.使用实验楼的虚拟机打开shell,用cd LinuxKernel/linux-3.9.4进入linux-3.9.4. 2.执行命令qemu - ...
- CALayer2-创建新的层
本文目录 一.添加一个简单的图层 二.添加一个显示图片的图层 三.为什么CALayer中使用CGColorRef和CGImageRef这2种数据类型,而不用UIColor和UIImage? 四.UIV ...
- numpy 的三角函数运算
numpy 的三角函数运算 cos, cosh, sin sinh, tan, tanh regular 和 hyperbolic 三角函数 arccos, arccosh, arcsin, arcs ...
- Python中super()和__init__()方法
采用新式类,要求最顶层的父类一定要继承于object,这样就可以利用super()函数来调用父类的init()等函数, 每个父类都执行且执行一次,并不会出现重复调用的情况.而且在子类的实现中,不用到处 ...
- 1.Python3关于文件的操作
1.写了一个简单的Demo,就是向txt文本写入内容,最初代码如下: file = open("D:/Users/nancy/python.txt","wb") ...