博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SIM820X 通过FTP实现阿里云文件共享
阅读量:3939 次
发布时间:2019-05-23

本文共 2629 字,大约阅读时间需要 8 分钟。

序言 :

FTP(File Transfer Protocol)是一种文件传输协议,一般是为了方便数据共享的;包括一个FTP服务器和多个FTP客户端,下面我们来一场FTP之旅:

准备工作

准备项 硬件准备 软件准备
1 阿里云轻量级服务器
2 sscom

工作流程

配置阿里云FTP服务器

  • 购买服务器,个人推荐 在这里插入图片描述

  • ,这里用到的镜像是Alyun Linux 2.19.03 在这里插入图片描述

  •  在轻量应用型服务器管理控制台->安全->防火墙->添加规则 在这里插入图片描述

  • 获取用户名和密码

bt default

在这里插入图片描述

  • 浏览器输入ip:8888->输入获取到的用户名和密码->登录宝塔面板 在这里插入图片描述
  • 安全->开放端口->1-65535 在这里插入图片描述
  • FTP->添加FTP->填上用户名和密码 image
  • 鼠标左击根目录->进入 image

SIM820X FTPS 通信

关键指令分析

  • start FTP service
AT+CFTPSSTART
  • set data connection use the sameaddress of control connection
AT+CFTPSSINGLEIP=1
  • login to a FTP server
AT+CFTPSLOGIN="120.79.2.0",21,"aly","root",0
  • list all items of directory “/”
AT+CFTPSLIST="/"
  • change current directory to "F:/"
AT+FSCD=F:/
  • list all items in "F:/"
AT+FSLS
  • upload file from"F:/" to FTP serve
AT+CFTPSPUTFILE="Code_204_NOK.qmdl"
  • download file from"F:/" to FTP serve
AT+CFTPSGETFILE="tower.png"

在电脑测试

下载文件到串口/从串口上传文件

imageimage

在树莓派测试

示例程序

#!/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服务器下载文件下载到模块/从模块上载文件

imageimage

阿里云FTP服务器收到文件

image

转载地址:http://maywi.baihongyu.com/

你可能感兴趣的文章
python中判断字符是否为中文
查看>>
Python - 利用zip函数将两个列表(list)组成字典(dict)
查看>>
python-全角转半角
查看>>
Python pass语句作用与用法
查看>>
Java double,float设置小数点位数
查看>>
PyCharm & Jupyter
查看>>
为什么要用Jupyter Notebook
查看>>
sklearn中的LogisticRegression模型
查看>>
pandas.get_dummies 的用法
查看>>
机器学习-训练模型的保存与恢复(sklearn)
查看>>
Spark(二): spark-submit命令详解
查看>>
细品 - 逻辑回归(LR)*
查看>>
hive: size与spilt连用
查看>>
Python:ModuleNotFoundError: No module named 模块名 错误及解决方案
查看>>
Python中os与sys两模块的区别
查看>>
nohup详解
查看>>
idea .gitignore对.idea不起作用解决
查看>>
深度学习中的注意力机制(2017版)-易理解
查看>>
Transformer解析-易理解
查看>>
多维数组[:,0]和[:0:1]获取的区别
查看>>