Using ftp

Verified
Added by iNTERFACEWARE

ftp commands to list, download, upload and rename files, the commands for ftps and sftp are similar

Source Code
   -- cache the connection parameters - substitute your ftp server details
   local FtpConn = net.ftp.init{server='example', username='user', password='password'}
   
   -- list directories
   FtpConn:list{remote_path=''}          -- users home directory
   FtpConn:list{remote_path='/'}         -- ftp root directory
   FtpConn:list{remote_path='/fox_out/'} -- user specified data directory
   
   -- get (download) files 
   
   -- get a text file (opens/closes an ASCII connection)
   FtpConn:get{remote_path='/fox_out/test.png',local_path='temp/test.txt'}   
   -- get a binary (picture) file (opens/closes a binary connection)
   FtpConn:get{remote_path='/fox_out/test.png',local_path='temp/test.png'}

   -- put (upload) files
   
   -- put a text file (opens/closes an ASCII connection)
   FtpConn:put{remote_path='/fox_in/test.png',local_path='temp/test.txt'}
   
   -- put a binary (picture) file (opens/closes a binary connection)
   FtpConn:put{remote_path='/fox_in/test.png',local_path='temp/test.png'}   
   
   -- rename a file
   FtpConn:rename{remote_path='/fox_out/test.txt', new_remote_path='/fox_processed/test_old.txt'}
Description
ftp commands to list, download, upload and rename files, the commands for ftps and sftp are similar
Usage Details

Examples for ftp commands to download (get), upload (put), list and rename files. The commands use a fictitious ftp server, you will need to substitute details for the ftp server you are using (and change the directory names to match those on the server).

Note: The commands for ftps and sftp are very similar

How to use the snippet:

  • Paste the code into your script
  • Change the ftp server details
  • Change directory names to match those used on your ftp server