Logic Machine Forum
Remote access to USB drive - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Remote access to USB drive (/showthread.php?tid=2896)



Remote access to USB drive - tassiebean - 10.10.2020

Hi,

I can write to a USB drive, then unplug it and read the contents on another computer. However, Is there a way to reads the USB drive contents remotely?

I was thinking to FTP in via the apps' credentials, and this allows me to see the /user directory. I can see files I have put into that directory via previous FTP sessions.

However, can I FTP my way to the USB contents? Or, as second best, how to write the code to copy a file from the USB dive to the /user directory, which I can then retrieve via FTP.

I have been playing with the following code:

Code:
-- Write a test USB stick file

res, err = mount_usb()

log('After mounting, result is', res, err)

if res then
  f, err = io.open('/mnt/testfile', 'a')
  if f ~= nil then
   
    f:write(os.date("Starting log at %X on %A, %d %B %Y")..'\n')
    for i = 1, 10 do
      f:write('Hello!'..'\n')
    end
    f:write(os.date("Finished log at %X on %A, %d %B %Y")..'\n')   
    f:close()
    log('Wrote to USB drive')

  else
    alert('Unable to write to file: ' .. err)
   
  end
  os.execute('cp /mnt/* /user') -- doesn't work
  os.execute('touch /user/Test.tst') -- doesn't work
  os.execute('touch /mnt/Test.tst') -- works!
  os.sleep(2)
  log('finished')
  unmount_usb()
 
else
  alert(err)
end

The first lot of code works and creates the 12 line file on the USB stick. The other os.execute commands either work or don't work as shown. Am I heading down the right path?

So, my questions summarised:
1) Can we reach the USB drive directly via FTP?
2) Failing that, can we copy files from the USB drive to the /user directory?

Thanks!


RE: Remote access to USB drive - Erwin van der Zwart - 10.10.2020

No, that is not possible, but you can write your file directly to the ftp

See this sample: https://openrb.com/example-export-last-hour-csv-object-log-file-to-external-ftp-server-from-lm2/


RE: Remote access to USB drive - tassiebean - 10.10.2020

Thanks, Erwin. There's a lot of examples and ideas there!


RE: Remote access to USB drive - admin - 12.10.2020

This is possible, you just need to mount the USB drive correctly. Note that example uses paths for ftp username, not apps. If using this approach you only need to mount USB drive once and do not unmount it after writing.
Code:
-- create directory.
os.execute('mkdir -p /data/ftp/usb')
-- mount usb drive
os.execute('mount /dev/sda1 /data/ftp/usb/ -o dmask=0000,fmask=0000')