python写的FTP工具

用Python写的FTP工具

import string
from ftplib import FTP
bufsize=1024
def Get(filename):
command='RETR '+filename
ftp.retrbinary(command,open(filename,'wb').write,bufsize)
print 'download successfully'
def Put(filename):
command='STOR '+filename
filehandler=open(filename,'rb')
ftp.storbinary(command,filehandler,bufsize)
filehandler.close()
print 'upload successfully'
def PWD():
print ftp.pwd()
def Size(filename):
print ftp.size(filename)
def Help():
print '''
==============================
Simple Python FTP
==============================
cd enter document
delete delete file
dir get files list
get download file
help help
mkdir create document
put upload file
pwd get current path
rename rename file name
rmdir delete document
size get file size
'''
server=raw_input('enter FTP server info: ')
ftp=FTP(server)
username=raw_input('username:')
password=raw_input('password')
ftp.login(username,password)
print ftp.getwelcome()
actions={'dir':ftp.dir,'pwd':PWD,'cd':ftp.cwd,'get':Get,
'put':Put,'help':Help,'rmdir':ftp.rmd,
'mkdir':ftp.mkd,'delete':ftp.delete,
'size':Size,'rename':ftp.rename}
while True:
print 'pyftp',
cmds=raw_input
cmd=string.split(cmds)
try:
if len(cmd)==1:
if string.lower(cmd[0])=='quit':
break
else:
actions[string.lower(cmd[0])]
elif len(cmd)==2:
actions[string.lower(cmd[0])](cmd[1])
elif len(cmd)==3:
actions[string.lower(cmd[0])](cmd[1],cmd[2])
else:
print 'type error'
except:
print 'command error'
ftp.quit()


随后我会写一个用Tkinter做的图形界面的版本
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值