python ftp 上传文件

发布时间:2019-08-12 09:51:44编辑:auto阅读(1864)

    python  ftp 上传文件


    #!/usr/bin/env python
    #-*- coding: utf-8 -*-
    from ftplib import FTP       #调用 模块
    import sys,getpass,os.path   #调用 模块
    host = '192.168.1.101'       #ftp地址
    port = 21              #端口号
    timenout = 30                #超时时间
    username = 'aping'           #ftp用户名
    password = '888888'          #ftp 密码
    localfile = '/tmp/lzp.txt'   #本机要上传的文件与路径
    remotepath = '/share/'       #ftp服务器的路径 (ftp://192.168.1.101/share)
    f = FTP()
    f.connect(host,port,timenout)  #连接ftp服务器
    f.login(username,password)     #登录ftp服务器
    f.cwd(remotepath)              #设置ftp服务器端的路径
    file = open(localfile,'rb')    #打开本地文件
    f.storbinary('STOR %s' % os.path.basename(localfile),file)  #上传文件到ftp服务器
    file.close()   #关闭本地文件
    f.quit()       #退出
     

关键字

上一篇: Notes for python (2)

下一篇: python守护进程