菜鸟学堂 -【Python Ftp】


一:官方doc

http://docs.python.org/py3k/library/ftplib.html#ftplib.FTP.transfercmd

二:

What Is the STOR command?

The STORE (STORcommand is used by the client to tell the server to accept the data transferred via the data connection and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, its contents are replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist.


三:

from ftplib import FTP

def upload():

    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    file = open("d:/1.jpg","rb")
    
    ftp.storbinary("stor abc.jpg",file)
    
    ftp.close()
    
def download():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    file = open("d:/download/d.jpg","wb")
    
    ftp.retrbinary("retr abc.jpg", file.write)
    
    ftp.close()
    
def list():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    ftp.dir()
    
    ftp.close()
    
def delete():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    ftp.delete("icts.jpg")
    
    ftp.close()
    
def rename():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    ftp.rename("icts.sql","new_icts.sql.bak")
    
    ftp.close()
    
def mkdir():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    ftp.mkd("nagat")
    
    ftp.close()
    
def rmdir():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    ftp.rmd("nagat")
    
    ftp.close()
    
def pwd():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    ftp.pwd()
    
    ftp.close()
    
def size():
    
    ftp = FTP("localhost")
    
    ftp.login("a", "a")
    
    s = ftp.size("1.exe")
    print(s)
    ftp.close()
    
    

#download()
#delete()
#rename()

#mkdir()
#rmdir()

#pwd()

size()
#list()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值