本文共 2629 字,大约阅读时间需要 8 分钟。
序言 :
FTP(File Transfer Protocol)是一种文件传输协议,一般是为了方便数据共享的;包括一个FTP服务器和多个FTP客户端,下面我们来一场FTP之旅:
准备项 | 硬件准备 | 软件准备 |
---|---|---|
1 | 阿里云轻量级服务器 | |
2 | sscom |
购买服务器,个人推荐
,这里用到的镜像是Alyun Linux 2.19.03
在轻量应用型服务器管理控制台->安全->防火墙->添加规则
获取用户名和密码
bt default
AT+CFTPSSTART
AT+CFTPSSINGLEIP=1
AT+CFTPSLOGIN="120.79.2.0",21,"aly","root",0
AT+CFTPSLIST="/"
AT+FSCD=F:/
AT+FSLS
AT+CFTPSPUTFILE="Code_204_NOK.qmdl"
AT+CFTPSGETFILE="tower.png"
下载文件到串口/从串口上传文件
#!/usr/bin/pythonimport serialimport timeser = serial.Serial("/dev/ttyUSB3",115200)ser.flushInput()rec_buff = ''ftp_user_name = 'aly'ftp_user_password = 'root'ftp_server = '120.79.2.0'download_file_name = 'hello.py'upload_file_name = 'hello.py'def send_at(command,back,timeout): rec_buff = '' ser.write((command+'\r\n').encode()) time.sleep(timeout) if ser.inWaiting(): time.sleep(0.1 ) rec_buff = ser.read(ser.inWaiting()) if rec_buff != '': if back not in rec_buff.decode(): print(command + ' ERROR') print(command + ' back:\t' + rec_buff.decode()) return 0 else: print(rec_buff.decode()) return 1 else: print(command + ' no responce')def configureFTP(server,u_name,u_password): send_at('AT+CFTPSSTART','OK',1) send_at('AT+CFTPSSINGLEIP=1','OK',1) #login to a FTP server send_at('AT+CFTPSLOGIN=\"'+ftp_server+'\",21,\"'+ftp_user_name+'\",\"'+ftp_user_password+'\",0','OK',1) #list all items of directory send_at('AT+CFTPSLIST=\"/\"','OK',1) send_at('AT+FSCD=F:/','OK',1) send_at('AT+FSLS','OK',1)def uploadToFTP(upload_file_name): print('upload file from FTP...') # creat the uploadfile send_at('AT+CFTRANRX=\"E:/'+upload_file_name+'\",12','OK',1) send_at('1314xal1314','OK',3) # update the uploadfile send_at('AT+CFTPSPUTFILE=\"'+upload_file_name+'\"','OK',1)def downloadFromFTP(download_file_name): print('Download file from FTP...') send_at('AT+CFTPSGETFILE=\"'+download_file_name+'\"','OK',1)try: configureFTP(ftp_server,ftp_user_name,ftp_user_password) time.sleep(2) print('Uploading file to \"'+ftp_server+'\"...') uploadToFTP(upload_file_name) time.sleep(3) print('Downloading file form \"'+ftp_server+'\"...') downloadFromFTP(download_file_name)except : if ser != None: ser.close()
FTPS从FTPS服务器下载文件下载到模块/从模块上载文件
转载地址:http://maywi.baihongyu.com/