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 ...
随机推荐
- spring同时操作多数据库 多个mysql和mongoDB,不需切换数据源,同时操作mysql和mongodb
源码:https://github.com/haihai1172/spring-mysql-mongoDB 项目目录 1.环境搭建,java-sdk 1.8 具体怎么搭建,就不说了 2.配置jdbc. ...
- 键盘优雅弹出与ios光标乱飘解决方案
前言 在移动开发中,会遇到这样的情况,比如说有一个输入框在最底部的时候,我们弹起输入框,输入框不会在输入键盘上. 说明白简单点就是,输入框被键盘挡住了.而且在原生中,输入框应该正好在输入键盘上,但是h ...
- git利用hooks实现自动部署
准备工作: 1.一台虚拟linux环境和window 开始工作 1.安装git(略) 2.创建git用户和创建test.git裸仓库 [root@localhost ~]# useradd -m gi ...
- 什么是aPaas?aPaas与低代码又是如何促进应用程序开发现代化的?
从软件即服务(SaaS)到基础设施即服务(IaaS),云计算的兴起使“一切皆服务”(XaaS)模型得以泛滥,而aPaaS可能是这些模型中最鲜为人知的模型.随着aPaaS市场预计将从2018年的近90亿 ...
- kmp-最小子串回文次数
poj 2406 Given two strings a and b we define a*b to be their concatenation. For example, if a = &quo ...
- postgresql gin索引使用
由于属于老项目,postgresql使用版本9.6,主要解决‘%name%"查询无法使用索引问题.pg_trgm模块提供函数和操作符测定字母,数字,文本基于三元模型匹配的相似性, 还有支持快 ...
- LeetCode 第七题--整数反转
1. 题目 2.思路 1. 题目 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123输出: 321 示例 2: 输入: -123输出: -321示例 ...
- Python学习,第六课 - 集合
Python中集合的相关操作 集合是一个无序的,不重复的数据组合 它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 list_1 =set ...
- js原型链和原型链的继承
每一个对象都有一个“_proto_”指针,指向实例化该对象的构造函数的原型对象,当该对象没有你想拿到的属性时,解释器会顺着指针不断向上找. 每一个构造你函数都有一个“prototype”属性,指向该构 ...
- 创建dynamics CRM client-side (四) - Namespace Notation in JS
我们在开发的时候会写很多functions. 但是这些functions 管理起来很麻烦. 微软内部建议我们使用namespace notation的形式管理我们的代码 // Converting f ...