FTP - File Transfer Protocol
FTP 实际上使用了两个 TCP 链接. 一个作为控制信道用, 主要传输一些指令和响应,
比如 ACK 或 错误码. 另一个链接是数据信道, 用来传输文件和一些诸如目录列表的
信息等. from ftplib import FTP, all_errors
FtpServerAddr = ''
user = ''
PW = ''
acct = '' FH = FTP(FtpServerAddr)
FH.login(user, PW, acct) # 不带参数表示 anonymous 登入 FH.getwelcome() # 获取问候语
FH.pwd() # 获取当前工作目录
FH.cwd() # 更换工作目录
FH.retrlines('cmd', 'callable') # 以 ASCII 模式下载, 文件被一行一行的传输.
# 一般 callable 是一个保存文件到本地的函数,
# 省略 callable, 数据将被打印到屏幕.
# cmd = 'RETR filename'
FH.retrbinary('cmd', 'callable', 'blocksize', 'rest')
# 以二进制模式下载数据
# If optional rest is given, a REST command is sent to the server,
# passing rest as an argument. rest is usually a byte offset into
# the requested file, telling the server to restart sending the file’s
# bytes at the requested offset, skipping over the initial bytes.
# Note however that RFC 959 requires only that rest be a string containing
# characters in the printable range from ASCII code 33 to ASCII code 126.
# The method, therefore, converts rest to a string, but no check is performed
# on the string’s contents. If the server does not recognize the REST command,
# an error_reply exception will be raised. If this happens, simply call method
# without a rest argument. FH.storbinary('cmd', 'FH', 'blocksize', 'callable', 'rest')
# 对应 socket 的 read() 方法, 二进制模式.
# cmd = 'STOR filename'
FH.storlines('cmd', 'FH', 'callable')
# 对应 socket 的 readline() 方法, ACSII 模式.
# cmd = 'STOR filename'
FH.nlst() # 获取路径下的条目
FH.dir() # 获取路径下的条目及相信信息, ls - la / dir FH.delete('filename') # 删除 filename 文件
FH.rmd('dirname') # 删除 dirname 目录
FH.mkd('dirname') # 建立 dirname 目录
FH.rename('fromname', 'toname') # 重命名
FH.quit() # 断开 FTP 链接 Error Handling,
ftplib.all_errors 包含累所有的有可能由 fitplib 产生的异常.
可以在 try: except 代码块中通过 ftplib.all_errors 来捕捉
处理可能发生的错误. Reference,
Python doc,
https://docs.python.org/3/library/ftplib.html

FTP - File Transfer Protocol的更多相关文章

  1. FTP(File Transfer Protocol)是什么?

    文件传输协议 FTP(File Transfer Protocol),是文件传输协议的简称.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(Application).用户可以通过 ...

  2. Trivial File Transfer Protocol (TFTP)

    Assignment 2The Trivial File Transfer Protocol (TFTP) is an Internet software utility fortransferrin ...

  3. TFTP(Trivial File Transfer Protocol,简单文件传输协议)

    TFTP(Trivial File Transfer Protocol,简单文件传输协议),是 TCP/IP 协议族中用来在客户机和服务器之间进行简单文件传输的协议,开销很小.这时候有人可能会纳闷,既 ...

  4. TFTP(Trivial File Transfer Protocol,简单文件传输协议)

    网络特性 通常使用UDP 69端口(据说可改成TCP) 与FTP区别 轻量级,适用于传输小文件,当然功能也少些,比如没有列出目录功能,不进行认证

  5. ftp - Internet 文件传输程序 (file transfer program)

    概述 (SYNOPSIS) ftp [-pinegvd ] [host ] pftp [-inegvd ] [host ] 说明 (DESCRIPTION) 用户通过 Ftp 这个程序来使用 Inte ...

  6. SSH File Transfer遇到错误"too many authentication failures for root".A protocol error was detected......

    在SSH  Secure Shell 连接Linux centos的时候,遇到F-Secure SSH File Transfer错误"too many authentication fai ...

  7. How to setup vsftpd FTP file Server on Redhat 7 Linux

    Forward from: https://linuxconfig.org/how-to-setup-vsftpd-ftp-file-server-on-redhat-7-linux How to s ...

  8. Hyper Text Transfer Protocol(超文本传输协议)

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  9. PAT 5-8 File Transfer (25分)

    We have a network of computers and a list of bi-directional connections. Each of these connections a ...

随机推荐

  1. ZooKeeper Java Example

    A Simple Watch Client Requirements Program Design The Executor Class The DataMonitor Class Complete ...

  2. 【移动测试】你的测试用例中,是否包含App前后台切换

    App前后台切换是我们平时常用的一个操作,比如:按手机的home键将应用置于后台.直接按手机电源键关闭屏幕或者通过最近打开的应用列表切换应用等,由此,我们可以得出结论:当app置于前台时,它的页面对我 ...

  3. hadoop搭建

    一.前期准备 1.1 静态ip,请查看虚拟机安装不放呢 1.2 hostname 以及 hosts文件修改 cat /etc/hostname 不同的机器设置不同的名字 cat /etc/hosts ...

  4. transient简介

    当一个对象实现了Serilizable接口,这个对象就可以被序列化,java的这种序列化模式为开发者提供了很多便利,我们可以不必关系具体序列化的过程,只要这个类实现了Serilizable接口,这个的 ...

  5. Redis Sentinel 高可用机制

    内容目录: Sentinel 如何工作的? 核心配置项 怎么选出新 master 的? Sentinel 有多个,具体谁来执行故障转移? Sentinel 是怎么发现 slave 和其他 sentin ...

  6. Egret学习-初次创建项目

    最近无聊,好久没有写游戏了,决定学习下egret,主要原因:egret是h5框架,相比android和iPhone或cocos2dx来说不需要安装可以直接运行. 下面进入正题,开始学习egret 简单 ...

  7. [bzoj4824][洛谷P3757][Cqoi2017]老C的键盘

    Description 老 C 是个程序员. 作为一个优秀的程序员,老 C 拥有一个别具一格的键盘,据说这样可以大幅提升写程序的速度,还能让写出来的程序 在某种神奇力量的驱使之下跑得非常快.小 Q 也 ...

  8. 可视化限流管理,Sentinel 控制台启动和接入

    Sentinel 的使用可以分为核心库和控制台两个部分. 核心库不依赖任何框架/库,集成了主流框架,可以进行单机限流降级等功能, 控制台Dashboard提供了可视化的管理限流规则.对集群进行监控,集 ...

  9. 约束路由 用正则表达式约束路由 Constraining a Route Using a Regular Expression 精通ASP-NET-MVC-5-弗瑞曼

  10. 并查集——奇偶性(Parity)

    题目描述 •有一个01序列,长度<=1000000000,现在有n条信息,每条信息的形式是-a b even/odd.表示第a位到第b位元素之间的元素总和是偶数/奇数. •你的任务是对于这些给定 ...