This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Remote access to USB drive
#1
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!
Reply
#2
No, that is not possible, but you can write your file directly to the ftp

See this sample: https://openrb.com/example-export-last-h...-from-lm2/
Reply
#3
Thanks, Erwin. There's a lot of examples and ideas there!
Reply
#4
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')
Reply


Forum Jump: