python使用ftplib库文件进行ftp上传和下载文件操作
import ftplib
def ftp_download_packet(server_ip,username,password,port,remote_path,local_path):
f = ftplib.FTP(server_ip)
f.login(username, password)
bufsize = 1024
fp = open(local_path, 'wb')
#print 'download start'+':'+local_path+':'+remote_path
f.retrbinary('RETR %s' % remote_path, fp.write, bufsize)
#print 'download end'+':'+local_path+':'+remote_path
fp.close()
f.quit()
def ftp_upload_packet(server_ip,username,password,port,remote_path,local_path):
f = ftplib.FTP(server_ip)
f.login(username, password)
bufsize = 1024
fp = open(local_path, 'wb')
#print 'upload start'+':'+local_path+':'+remote_path
f.storbinary('STOR ' + remote_path, fp, bufsize)
#print 'upload end'+':'+local_path+':'+remote_path
fp.close()
f.quit()
1602

被折叠的 条评论
为什么被折叠?



