#!/usr/bin/env python
# ftpserver.py
#
# pyftpdlib is released under the MIT license, reproduced below:
# ======================================================================
# Copyright (C) 2007 Giampaolo Rodola' <g.rodola@gmail.com>
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# Giampaolo Rodola' not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# Giampaolo Rodola' DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT Giampaolo Rodola' BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ======================================================================
"""pyftpdlib: RFC-959 asynchronous FTP server.
pyftpdlib implements a fully functioning asynchronous FTP server as
defined in RFC-959. A hierarchy of classes outlined below implement
the backend functionality for the FTPd:
[FTPServer] - the base class for the backend.
[FTPHandler] - a class representing the server-protocol-interpreter
(server-PI, see RFC-959). Each time a new connection occurs
FTPServer will create a new FTPHandler instance to handle the
current PI session.
[ActiveDTP], [PassiveDTP] - base classes for active/passive-DTP
backends.
[DTPHandler] - this class handles processing of data transfer
operations (server-DTP, see RFC-959).
[DummyAuthorizer] - an "authorizer" is a class handling FTPd
authentications and permissions. It is used inside FTPHandler class
to verify user passwords, to get user's home directory and to get
permissions when a filesystem read/write occurs. "DummyAuthorizer"
is the base authorizer class providing a platform independent
interface for managing virtual users.
[AbstractedFS] - class used to interact with the file system,
providing a high level, cross-platform interface compatible
with both Windows and UNIX style filesystems.
[AuthorizerError] - base class for authorizers exceptions.
pyftpdlib also provides 3 different logging streams through 3 functions
which can be overridden to allow for custom logging.
[log] - the main logger that logs the most important messages for
the end user regarding the FTPd.
[logline] - this function is used to log commands and responses
passing through the control FTP channel.
[logerror] - log traceback outputs occurring in case of errors.
Usage example:
>>> from pyftpdlib import ftpserver
>>> authorizer = ftpserver.DummyAuthorizer()
>>> authorizer.add_user('user', 'password', '/home/user', perm='elradfmw')
>>> authorizer.add_anonymous('/home/nobody')
>>> ftp_handler = ftpserver.FTPHandler
>>> ftp_handler.authorizer = authorizer
>>> address = ("127.0.0.1", 21)
>>> ftpd = ftpserver.FTPServer(address, ftp_handler)
>>> ftpd.serve_forever()
Serving FTP on 127.0.0.1:21
[]127.0.0.1:2503 connected.
127.0.0.1:2503 ==> 220 Ready.
127.0.0.1:2503 <== USER anonymous
127.0.0.1:2503 ==> 331 Username ok, send password.
127.0.0.1:2503 <== PASS ******
127.0.0.1:2503 ==> 230 Login successful.
[anonymous]@127.0.0.1:2503 User anonymous logged in.
127.0.0.1:2503 <== TYPE A
127.0.0.1:2503 ==> 200 Type set to: ASCII.
127.0.0.1:2503 <== PASV
127.0.0.1:2503 ==> 227 Entering passive mode (127,0,0,1,9,201).
127.0.0.1:2503 <== LIST
127.0.0.1:2503 ==> 150 File status okay. About to open data connection.
[anonymous]@127.0.0.1:2503 OK LIST "/". Transfer starting.
127.0.0.1:2503 ==> 226 Transfer complete.
[anonymous]@127.0.0.1:2503 Transfer complete. 706 bytes transmitted.
127.0.0.1:2503 <== QUIT
127.0.0.1:2503 ==> 221 Goodbye.
[anonymous]@127.0.0.1:2503 Disconnected.
"""
import asyncore
import asynchat
import socket
import os
import sys
import traceback
import errno
import time
import glob
import fnmatch
import tempfile
import warnings
import random
import stat
from tarfile import filemode
try:
import pwd
import grp
except ImportError:
pwd = grp = None
__all__ = ['proto_cmds', 'Error', 'log', 'logline', 'logerror', 'DummyAuthorizer',
'FTPHandler', 'FTPServer', 'PassiveDTP', 'ActiveDTP', 'DTPHandler',
'FileProducer', 'IteratorProducer', 'BufferedIteratorProducer',
'AbstractedFS',]
__pname__ = 'Python FTP server library (pyftpdlib)'
__ver__ = '0.4.0'
__date__ = '2008-05-16'
__author__ = "Giampaolo Rodola' <g.rodola@gmail.com>"
__web__ = 'http://code.google.com/p/pyftpdlib/'
proto_cmds = {
'ABOR': 'Syntax: ABOR (abort transfer).',
'ALLO': 'Syntax: ALLO <SP> bytes (obsolete; allocate storage).',
'APPE': 'Syntax: APPE <SP> file-name (append data to an existent file).',
'CDUP': 'Syntax: CDUP (go to parent directory).',
'CWD' : 'Syntax: CWD <SP> dir-name (change current working directory).',
'DELE': 'Syntax: DELE <SP> file-name (delete file).',
'EPRT': 'Syntax: EPRT <SP> |proto|ip|port| (set server in extended active mode).',
'EPSV': 'Syntax: EPSV [<SP> proto/"ALL"] (set server in extended passive mode).',
'FEAT': 'Syntax: FEAT (list all new features supported).',
'HELP': 'Syntax: HELP [<SP> cmd] (show help).',
'LIST': 'Syntax: LIST [<SP> path-name] (list files).',
'MDTM': 'Syntax: MDTM <SP> file-name (get last modification time).',
'MLSD': 'Syntax: MLSD [<SP> dir-name] (list files in a machine-processable form)',
'MLST': 'Syntax: MLST [<SP> path-name] (show a path in a machine-processable form)',
'MODE': 'Syntax: MODE <SP> mode (obsolete; set data transfer mode).',
'MKD' : 'Syntax: MDK <SP> dir-name (create directory).',
'NLST': 'Syntax: NLST [<SP> path-name] (list files in a compact form).',
'NOOP': 'Syntax: NOOP (just do nothing).',
'OPTS': 'Syntax: OPTS <SP> ftp-command [<SP> option] (specify options for FTP commands)',
'PASS': 'Syntax: PASS <SP> user-name (set user password).',
'PASV': 'Syntax: PASV (set server in passive mode).',
'PORT': 'Syntax: PORT <sp> h1,h2,h3,h4,p1,p2 (set server in active mode).',
'PWD' : 'Syntax: PWD (get current working directory).',
'QUIT': 'Syntax: QUIT (quit current session).',
'REIN': 'Syntax: REIN (reinitialize / flush account).',
'REST': 'Syntax: REST <SP> marker (restart file position).',
'RETR': 'Syntax: RETR <SP> file-name (retrieve a file).',
'RMD' : 'Syntax: RMD <SP> dir-name (remove directory).',
'RNFR': 'Syntax: RNFR <SP> file-name (file renaming (source name)).',
'RNTO': 'Syntax: RNTO <SP> file-name (file renaming (destination name)).',
'SIZE': 'Syntax: HELP <SP> file-name (get file size).',
'STAT': 'Syntax: STAT [<SP> path name] (status information [list files]).',
'STOR': 'Syntax: STOR <SP> file-name (store a file).',
'STOU': 'Syntax: STOU [<SP> file-name] (store a file with a unique name).',
'STRU': 'Syntax: STRU <SP> type (obsolete; set file structure).',
'SYST': 'Syntax: SYST (get operating system type).',
'TYPE': 'Syntax: TYPE <SP> [A | I] (set transfer type).',
'USER': 'Syntax: USER <SP> user-name (set username).',
'XCUP': 'Syntax: XCUP (obsolete; go to parent directory).',
'XCWD': 'Syntax: XCWD <SP> dir-name (obsolete; change current directory).',
'XMKD': 'Syntax: XMDK <SP> dir-name (obsolete; create directory).',
'XPWD': 'Syntax: XPWD (obsolete; get current dir).',
'XRMD': 'Syntax: XRMD <SP> dir-name (obsolete; remove di
python ftplib
4星 · 超过85%的资源 需积分: 12 34 浏览量
2008-09-26
14:11:11
上传
评论 1
收藏 67KB GZ 举报
tigeryt007
- 粉丝: 0
- 资源: 13
最新资源
- week6.1.7z
- 移动机器人自主路径规划之RRTStar算法MATLAB实现代码
- 基于Python+OpenCV+FFmpeg实现自动识别电影剪辑+分析剪辑主题颜色+源码+文档(毕业设计&课程设计&项目开发)
- 基于python的二手商品交易平台 python+django开发的供需平台
- 微信小程序源码 侧滑布局小程序 (源码下载 +内附使用说明)
- heima-JUC-资料
- coreg_FSL.sh
- ROS+YOLOV8+SLAM智能小车导航实战(四、激光雷达+SLAM建图)
- 什么是决策树,有哪些适用场景?
- 基于python开发的口红色号识别程序+源码+开发文档+源码解析(毕业设计&课程设计&项目开发)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈