from ftplib import FTP
import sys
def ftpdownload(path,file):
ftp = FTP()
ftp.set_debuglevel(2)
#打开调试级别2,显示详细信息
ftp.connect('**IP**')
#连接ftp服务器
ftp.login(user,password)
#输入用户名和密码
print ftp.getwelcome()
#显示ftp服务器的欢迎信息
ftp.cwd(path)
#选择操作目录
bufsize = 1024
#设置缓冲区大小
file_handler = open(file,'wb').write
#以写模式在本地打开文件
strBuffer = 'RETR ' + file
ftp.retrbinary(strBuffer,file_handler,bufsize)
#接收服务器上文件并写入本地文件
ftp.set_debuglevel(0) #关闭调试
ftp.quit() #退出ftp服务器
if __name__ == '__main__':
path1 = 'download/test/'
file1 = 'test1.rar'
if len(sys.argv) == 3:
try:
ftpdownload(sys.argv[1],sys.argv[2])
#命令行输入文件在ftp上的路径和文件名,
except IOError:
print "please input the correct path and filename"
else:
ftpdownload(path1,file1)
from ftplib import FTP
import sys,os
def ftpdownload(path,file):
ftp = FTP()
ftp.set_debuglevel(2)
ftp.connect('**IP**')
ftp.login(user,password)
print ftp.getwelcome()
ftp.cwd(path)
bufsize = 1024
file_handler = open(file,'rb')
#读方式打开上传文件
strBuffer = 'RETR ' + file
ftp.storbinary(strBuffer,file_handler,bufsize)
#上传文件
ftp.set_debuglevel(0)
ftp.quit()
if __name__ == '__main__':
path1 = 'download/test/'
file1 = '4.jpg'
if len(sys.argv) == 3:
try:
ftpdownload(sys.argv[1],sys.argv[2])
except IOError:
print "please input the correct path and filename"
else:
ftpdownload(path1,file1)
import urllib
import sys
def download(url):
starttime = datetime.datetime.now()
print 'download start time is %s'% starttime
urllib.urlretrieve(url,'test.exe')
#开始下载,test.exe为下载后保存的文件名
endtime = datetime.datetime.now()
print 'download end time is %s'% endtime
print 'you download the file use time %s s' % (endtime - starttime).seconds
if __name__ == '__main__':
if len(sys.argv) == 2:
try:
download(sys.argv[1])
except IOError:
print 'url not found'
else:
download('http://www.python.org/')
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有