from ftplib import FTP

ftp = FTP('ftp.abc.com')
ftp.login(user='username', passwd='********')
ftp.cwd('/path') #entry directory path
# ftp.retrlines('LIST')
files = ftp.dir()
print(files)
ftp.quit() def grabFile():
"""
Download filename to local current folder with name localfile
""" filename = 'CAP2'
localfile = open('CAP2COPY', 'wb')
ftp.retrbinary('RETR ' + filename, localfile.write, 1024)
print('Download is finished!')
ftp.quit()
localfile.close() # grabFile() def placeFile():
"""
Upload filename to ftp server with same filename
""" filename = 'example.ini'
ftp.storbinary('STOR '+filename, open(filename, 'rb'))
ftp.quit() # placeFile() def deleteFile():
"""
Delete filename from ftp server
""" filename = 'example.ini'
ftp.delete(filename)
files = ftp.dir()
print(files)
ftp.quit() # deleteFile()

参考:

https://www.pythonforbeginners.com/code-snippets-source-code/how-to-use-ftp-in-python/

https://pythonprogramming.net/ftp-transfers-python-ftplib/

转载于:https://www.cnblogs.com/forcheny/p/10209615.html

python操作ftp文件的更多相关文章

  1. Python操作Zip文件

    Python操作Zip文件 需要使用到zipfile模块 读取Zip文件 随便一个zip文件,我这里用了bb.zip,就是一个文件夹bb,里面有个文件aa.txt. import zipfile # ...

  2. Python 基于Python实现Ftp文件上传,下载

    基于Python实现Ftp文件上传,下载   by:授客 QQ:1033553122 测试环境: Ftp客户端:Windows平台 Ftp服务器:Linux平台 Python版本:Python 2.7 ...

  3. python操作txt文件中数据教程[4]-python去掉txt文件行尾换行

    python操作txt文件中数据教程[4]-python去掉txt文件行尾换行 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文章 python操作txt文件中数据教程[1]-使用pyt ...

  4. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  5. python操作txt文件中数据教程[2]-python提取txt文件

    python操作txt文件中数据教程[2]-python提取txt文件中的行列元素 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果-将txt中元素提取并保存在c ...

  6. python操作txt文件中数据教程[1]-使用python读写txt文件

    python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = '. ...

  7. 使用python操作FTP上传和下载

    函数释义 Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件,函数列举如下 ftp登陆连接 from ftplib import F ...

  8. python 操作Excel文件

    1   安装xlrd.xlwt.xlutils cmd下输入: pip install xlrd        #读取excel pip install xlwt        #写入excel pi ...

  9. python操作xml文件

    一.什么是xml? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. abc.xml <?xml version="1.0&q ...

随机推荐

  1. vscode 保存自动 格式化eslint 代码

    在网上找了很多种方法,大多都没有成功  一下是一种成功的 配置方法: 1) First, you need to install the ESLint extension in the VS code ...

  2. 1050 String Subtraction (20分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  3. PTA数据结构与算法题目集(中文) 7-7

    PTA数据结构与算法题目集(中文)  7-7 7-7 六度空间 (30 分)   “六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论.这个理论可以通俗地阐述为 ...

  4. Mysql千万级记录表分表策略

    目前,比较流行的分表为2倍扩容. 表A(id, name, age, sex) 基于自增id分表, 通过触发器先同步A到B, 程序通过mod 2操作数据,然后drop掉触发器,在 删除两个A表的偶数i ...

  5. 【php】面向对象(一)

    1. 学习面向对象的目标: a) 语法的学习: b) 编程思想的学习: i. 过程化: ii. 面向对象:2. 比较(有对象和没对象的区别) a) 没对象: i. 我饿了 自己做饭 ii. 我渴了 自 ...

  6. flask-include、set、with、模板继承

    flask-include.set.with include: 跟django的include类似,将一个html的代码块直接嵌入另一个html文件中 {%   include    'html    ...

  7. wireshark抓包实战(一),抓包原理

    一.什么样的"包"能被wireshark抓住呢? 1.本机 即直接抓取进出本机网卡的流量包.这种情况下,wireshark会绑定本机的一块网卡. 2.集线器 用于抓取流量泛洪,冲突 ...

  8. 插入排序(C语言版)

    #include<iostream>using namespace std;int n;void lan(int a[],int size){ for(int i = 0;i < s ...

  9. jvm入门及理解(二)——类加载器子系统

    一.类加载子系统的作用 类加载子系统负责从文件系统或者网络中加载Class文件,class文件在文件开头有特定的文件标识: ClassLoader只负责class文件的加载,至于它是否可以运行,则由E ...

  10. hive常用函数三

    日期函数 1. UNIX时间戳转日期函数: from_unixtime 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string ...