[python] 使用ftplib模块在交互式窗口下连接FTP的练习
来源:互联网 发布:宣传册软件 编辑:程序博客网 时间:2024/05/20 09:44
ftplib是 Python的内置的一个标准模块,它提供了极强大的对FTP服务器的操作,通过它我们可以连接并操作FTP服务端,开始练习:
一、导入模块并进行连接
>>> from ftplib import FTP
>>> ftp = FTP(‘ftp.yabogo.com’)
>>> ftp.login(‘yourloginname’,'password’)
连接到FTP可还有如下形式:
1、实例化并直接连接,ftp=FTP(host=”, user=”, passwd=”, acct=”, timeout=”)
2、先实例ftp=FTP(), 再使用 connect(host=”, port=0, timeout=-999)连接,最后login(user=”, passwd=”)
二、查看目录文件或更改目录
>>> ftp.retrlines(‘LIST’)
1、retrlines(cmd)是以文本形式查看当前目录文件,可用cmd:RETR, LIST, NLST, MLSD
2、如果要指定查看某个目录的文件列表,可以用dir(dirname) ,dirname是可选参数,默认是当前目录;
3、cwd(dirname), 更改目录! Change to a directory.
三、查看文件的大小
>>> ftp.size(‘yabogo_logo.gif’)
2452
四、上传一个文件
>>> fp=open(‘F:/test.php’,'rb’)
>>> ftp.storbinary(‘STOR test.php’,fp)
storbinary( cmd, fp, blocksize=8192, callback=None, rest=None)
Args:
cmd: A STOR command.
fp: A file-like object with a read(num_bytes) method.
blocksize: The maximum data size to read from fp and send over
the connection at once. [default: 8192]
callback: An optional single parameter callable that is called on
on each block of data after it is sent. [default: None]
rest: Passed to transfercmd(). [default: None]
Returns:
The response code.
五、退出关闭,并退出FTP
>>> ftp.quit()
’221 Goodbye, logging out.’
ftplib有很多可用的方法,导入模块后可通过help()查看帮助信息。
- [python] 使用ftplib模块在交互式窗口下连接FTP的练习
- 基于ftplib的交互式ftp客户端实现
- python的ftplib模块
- python使用ftplib模块实现ftp目录嵌套下载
- 用python的ftplib模块编写ftp客户端程序
- 用python的ftplib模块编写ftp客户端程序
- python的学习---- ftplib模块 .
- python使用ftplib做ftp操作
- python 利用ftplib模块 实现ftp上传下载代码
- python的学习(十三)---- ftplib模块
- Python ftplib模块
- Python中的ftplib模块
- Python ftplib模块
- python ftplib模块
- ftplib模块--编写ftp客户端程序
- Python中的ftplib模块调用与测试
- ftplib模块
- ftplib模块
- 成功在CentOs下编译安装SVN
- 【Android UI设计与开发】第03期:引导界面(三)仿微信引导界面以及动画效果
- COleDateTime ParseDateTime 方法
- SYS_CONNECT_BY_PATH函数用法 ORACLE
- Ubuntu 12.04搭建hadoop2.0.4单机版环境
- [python] 使用ftplib模块在交互式窗口下连接FTP的练习
- XML的序列化和反序列化
- C中调用C++与C++调用C
- Notification与NotificationManager详细介绍
- Android Studio 的快捷键
- 闲来无事
- 触发器
- Spring MVC框架
- 当时我就无语了啊