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 ...
随机推荐
- mailto web弹出outlook发送邮件
1. <pre name="code" class="html"><a href="Mailto:test@163.com?CC=t ...
- restful 协议 +面试
restful 协议:面向资源软件架构风格 API 定义 一些预先定义的函数,目的是能够让应用程序或开发人员能够具有访问指定网络资源的能力,而无需关心访问的远吗以及内部的工作机制细节. RESTful ...
- 特性属性 @property
实现其它语言所拥有的 getter 和 setter 的功能 作用: 用来模拟一个属性 通过@property 装饰器可以对模拟属性的取值和赋值加以控制 class Student: def __in ...
- 2017年 ACM Journal Latex templates 新模板生成 acmart.cls 文件
假定你的文稿在:/user/acmart-master那么cd /user/acmart-masterlatex acmart.ins最后可得到acmart.cls.
- linux自学(三)之开启虚拟机
上一篇:linux自学(二)之centos7镜像安装 前面都已经铺垫好了,下面就是开始安装镜像了,真正的开启一台linux机器. 点击开启此虚拟机,如图: 之后就是等待了,然后就是开始配置,首先如下图 ...
- BZOJ2038 2009国家集训队 小Z的袜子(hose) 【莫队】
BZOJ2038 2009国家集训队 小Z的袜子(hose) Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼 ...
- BZOJ2330 SCOI2011 糖果 【差分约束】
BZOJ2330 SCOI2011 糖果 Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一 ...
- 报错 Inferred type 'S' for type parameter 'S' is not within its bound; 解决办法
出现情况: Inferred type 'S' for type parameter 'S' is not within its bound; should extends xxxxxx 出现这种问题 ...
- DVD项目
package sy.com.cn;import java.util.*; public class DvdWorker { public static void main(String[]args) ...
- Hadoop1.x安装配置文件及参数说明
一.常用文件及参数说明Core-site.xml 配置Common组件的属性 hdfs-site.xml 配置hdfs参数,比如备份数目,镜像存放路径 Mapred-sit ...