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 ...
随机推荐
- [Linux] 随机切分文件内容
1.从原文件中随机选出若干行 可以直接用shuf命令就可以完成: $ shuf -n source.txt > target.txt shuf命令的说明: $ shuf --help Usage ...
- Git详解之五 分布式Git
以下内容转载自:http://www.open-open.com/lib/view/open1328070090108.html 分布式 Git 为了便于项目中的所有开发者分享代码,我们准备好了一台服 ...
- scala学习笔记(9): 语法续
1 不定长参数 def sum(args: Int*) = { var result = 0 for ( arg <- args) result += arg result } 2 数组初始化 ...
- scrapy与scrapyd安装
Scrapy是用python编写的爬虫程序. Scrapyd是一个部署与运行scrapy爬虫的应用,提供JSON API的调用方式来部署与控制爬虫 . 本文验证在fedora与centos是安装成功. ...
- 【模板】FFT
FFT模板 安利一下前辈的博客,写的真的好点击这里:从多项式乘法到快速傅里叶变换 #include<bits/stdc++.h> using namespace std; const in ...
- KeyDown/PreviewKeyDown事件中监听Alt键按下
一个坑 在WPF应用程序(或者其他Windows应用程序中),为了监听Alt键按下,我们可以尝试写出这样的代码: PreviewKeyDown += (s, e) => { if (e.Key ...
- 部署经验Docker
从Docker 到Jenkins 到Ansible的部署经验 https://www.cnblogs.com/itdragon/p/10011816.html 工作中,除了开发功能,还负责系统的部署工 ...
- 静态分析工具PMD使用说明
质量是衡量一个软件是否成功的关键要素.而对于商业软件系统,尤其是企业应用软件系统来说,除了软件运行质量.文档质量以外,代码的质量也是非常重要的.软件开发进行到编码阶段的时候,最大的风险就在于如何保证代 ...
- scrapy模拟浏览器爬取验证码页面
使用selenium模块爬取验证码页面,selenium模块需要另外安装这里不讲环境的配置,我有一篇博客有专门讲ubuntn下安装和配置模拟浏览器的开发 spider的代码 # -*- coding: ...
- 【angularJS】MVC
angularJS中的mvc是借助于$scope实现的. View(视图), 即 HTML. Model(模型), 当前视图中可用的数据.scope 是模型.scope 是一个 JavaScript ...