main.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "ftpdemo"
  3. VERSION = "1.0.0"
  4. --[[
  5. 本demo需要ftp库, 大部分能联网的设备都具有这个库
  6. ftp也是内置库, 无需require
  7. ]]
  8. -- sys库是标配
  9. _G.sys = require("sys")
  10. --[[特别注意, 使用ftp库需要下列语句]]
  11. _G.sysplus = require("sysplus")
  12. sys.taskInit(function()
  13. -----------------------------
  14. -- 统一联网函数, 可自行删减
  15. ----------------------------
  16. if wlan and wlan.connect then
  17. -- wifi 联网, ESP32系列均支持
  18. local ssid = "luatos1234"
  19. local password = "12341234"
  20. log.info("wifi", ssid, password)
  21. -- TODO 改成esptouch配网
  22. -- LED = gpio.setup(12, 0, gpio.PULLUP)
  23. wlan.init()
  24. wlan.setMode(wlan.STATION)
  25. wlan.connect(ssid, password, 1)
  26. local result, data = sys.waitUntil("IP_READY", 30000)
  27. log.info("wlan", "IP_READY", result, data)
  28. device_id = wlan.getMac()
  29. -- TODO 获取mac地址作为device_id
  30. elseif mobile then
  31. -- Air8000/Air600E系列
  32. --mobile.simid(2)
  33. -- LED = gpio.setup(27, 0, gpio.PULLUP)
  34. device_id = mobile.imei()
  35. sys.waitUntil("IP_READY", 30000)
  36. end
  37. -- -- 打印一下支持的加密套件, 通常来说, 固件已包含常见的99%的加密套件
  38. -- if crypto.cipher_suites then
  39. -- log.info("cipher", "suites", json.encode(crypto.cipher_suites()))
  40. -- end
  41. while true do
  42. sys.wait(1000)
  43. log.info("ftp 启动")
  44. print(ftp.login(nil,"121.43.224.154",21,"ftp_user","3QujbiMG").wait())
  45. print(ftp.command("NOOP").wait())
  46. print(ftp.command("SYST").wait())
  47. print(ftp.command("TYPE I").wait())
  48. print(ftp.command("PWD").wait())
  49. print(ftp.command("MKD QWER").wait())
  50. print(ftp.command("CWD /QWER").wait())
  51. print(ftp.command("CDUP").wait())
  52. print(ftp.command("RMD QWER").wait())
  53. print(ftp.command("LIST").wait())
  54. -- io.writeFile("/1222.txt", "23noianfdiasfhnpqw39fhawe;fuibnnpw3fheaios;fna;osfhisao;fadsfl")
  55. -- print(ftp.push("/1222.txt","/12222.txt").wait())
  56. print(ftp.pull("/122224.txt","/122224.txt").wait())
  57. local f = io.open("/122224.txt", "r")
  58. if f then
  59. local data = f:read("*a")
  60. f:close()
  61. log.info("fs", "writed data", data)
  62. else
  63. log.info("fs", "open file for read failed")
  64. end
  65. print(ftp.command("DELE /12222.txt").wait())
  66. print(ftp.push("/122224.txt","/12222.txt").wait())
  67. print(ftp.close().wait())
  68. log.info("meminfo", rtos.meminfo("sys"))
  69. sys.wait(15000)
  70. end
  71. end)
  72. -- 用户代码已结束---------------------------------------------
  73. -- 结尾总是这一句
  74. sys.run()
  75. -- sys.run()之后后面不要加任何语句!!!!!