ftp 操作

#!/usr/bin/python
# coding: utf-8

import ftplib

def printList(lines):
    print (lines.split())

# init, connect & login
ftp = ftplib.FTP()
ftp.connect(ip, port)
ftp.login(user, passwd)

# list files
ftp.dir(printList)

# download remote file to local
ftp.cwd(remote_dir)
f = open(local_file, 'wb')
ftp.retrbinary('PETR %s' % (remote_file), f.write)
f.close()

# upload local file to remote
ftp.cwd(remote_dir)
f = open(local_file, 'rb')
ftp.storbinary('STOR %s' % (remote_file), f)
f.close()

# disconnect
ftp.close()

results matching ""

    No results matching ""