130ftp-python3 FTP简单实现文件下载(含中文乱码问题)
130ftp-python3 FTP简单实现文件下载(含中文乱码问题)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from ftplib import FTP
def ftp_down(HOST,romatepath,filename,localpath):
user = * * * * *
password = * * * * *
ftp = FTP(HOST) #连接远程服务器IP地址
ftp.encoding = 'utf-8' #解决中文乱码问题
ftp.login(user,password)
#print (ftp.getwelcome())#显示ftp服务器欢迎信息
ftp.cwd(romatepath) #选择操作目录
bufsize = 1024
file_handler = open (localpath, 'wb' ).write #以写模式在本地打开文件
ftp.retrbinary( 'RETR %s' % filename,file_handler,bufsize)
ftp.quit()
print ( "ftp down OK" )
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from ftplib import FTP
def ftp_down(HOST,romatepath,filename,localpath):
user = * * * * *
password = * * * * *
ftp = FTP(HOST) #连接远程服务器IP地址
ftp.encoding = 'utf-8' #解决中文乱码问题
ftp.login(user,password)
#print (ftp.getwelcome())#显示ftp服务器欢迎信息
ftp.cwd(romatepath) #选择操作目录
bufsize = 1024
file_handler = open (localpath, 'wb' ).write #以写模式在本地打开文件
ftp.retrbinary( 'RETR %s' % filename,file_handler,bufsize)
ftp.quit()
print ( "ftp down OK" )
|