FTP - File Transfer Protocol
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的更多相关文章
- FTP(File Transfer Protocol)是什么?
文件传输协议 FTP(File Transfer Protocol),是文件传输协议的简称.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(Application).用户可以通过 ...
- Trivial File Transfer Protocol (TFTP)
Assignment 2The Trivial File Transfer Protocol (TFTP) is an Internet software utility fortransferrin ...
- TFTP(Trivial File Transfer Protocol,简单文件传输协议)
TFTP(Trivial File Transfer Protocol,简单文件传输协议),是 TCP/IP 协议族中用来在客户机和服务器之间进行简单文件传输的协议,开销很小.这时候有人可能会纳闷,既 ...
- TFTP(Trivial File Transfer Protocol,简单文件传输协议)
网络特性 通常使用UDP 69端口(据说可改成TCP) 与FTP区别 轻量级,适用于传输小文件,当然功能也少些,比如没有列出目录功能,不进行认证
- ftp - Internet 文件传输程序 (file transfer program)
概述 (SYNOPSIS) ftp [-pinegvd ] [host ] pftp [-inegvd ] [host ] 说明 (DESCRIPTION) 用户通过 Ftp 这个程序来使用 Inte ...
- 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 ...
- 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 ...
- Hyper Text Transfer Protocol(超文本传输协议)
HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...
- PAT 5-8 File Transfer (25分)
We have a network of computers and a list of bi-directional connections. Each of these connections a ...
随机推荐
- luogu 题解 P2380 【狗哥采矿】
拿到dp题我们就要想如何推方程 “最北边有bloggium的收集站,最西边有 yeyenum 的收集站.现在要你在这些格子上面安装向北或者向西的传送带(每个格子只能装一种).” 这说明了什么,对于某一 ...
- 原生js面向对象编程-选项卡(点击)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- python 多进程处理图像,充分利用CPU
默认情况下,Python程序使用一个CPU以单个进程运行.不过如果你是在最近几年配置的电脑,通常都是四核处理器,也就是有8个CPU.这就意味着在你苦苦等待Python脚本完成数据处理工作时,你的电脑其 ...
- vs删除空白行 注释
在vs编辑器中有时需要批量删除无用的空白行,为此,可以使用vs编辑器的查找替换功能: 1. Ctrl+H,打开替换功能框. 2.选择“使用正则表达式”,“当前文档”. 3.在查找框中输入: (?< ...
- python中property和setter装饰器
property和setter装饰器 作用:调用方法改为调用对象, 比如 : p.set_name() 改为 p.set_name 区别: 前者改变get方法,后者改变set方法 效果图 ...
- 被裁的第50天,我终于拿到心仪公司Offer
今天分享的是之前分享文章中被裁的小C,可以看这篇文<寒冬之下,被cai的那些人到底去哪了?>,最近他已经找到心仪公司今日头条Offer,并且即将入职,在应我要求下,他写了篇总结文如下.下文 ...
- RocketMQ客户端加载流程
这节介绍RocketMQ客户端的启动流程,即Consumer和Producer的启动流程. 1. 客户端demo 首先先看下客户端的demo Producer: public class Sync ...
- LeetCode 第27题--移除元素
1. 题目 2.题目分析与思路 3.代码 1. 题目 给定 nums = [3,2,2,3], val = 3, 函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2. 你不需要考虑数组 ...
- python 面向对象的内置方法
要求:了解即可,能用最好 """ 1.print(obj), str(obj), %s % (obj), 都调用obj.__str__()方法,若类中没有找__repr_ ...
- 7.Java帝国的诞生
1972年,C诞生,而Java是1995年诞生的.它贴近硬件,有汇编语言的特性,运行极快,效率极高.早期,用在操作系统.编译器.数据库.网络系统等.但它有两把沉重的枷锁一直在程序员身上,那就是指针和内 ...