title: Get the latest file from a remote server from an FTP in Unix
body: <p>I need to get a file from a remote host in Unix. I am using the <code>ftp</code> command. The issue is I need the latest file from that location. This is how I am doing it:</p>
  
  <pre><code>dir=/home/user/nyfolders
  latest_file=$(ls  *abc.123.* | tail -1)
  ftp -nv &lt;&lt;EOF
  open $hostname
  user $username $password
  binary
  cd $dir
  get $latest_file
  bye
  EOF
  </code></pre>
  
  <p>But I get this error: </p>
  
  <pre><code>(remote-file) usage: get remote-file [ local-file ]
  </code></pre>
  
  <p>I think the way I am trying to get the file from within the <code>ftp</code> command is incorrect, can someone please help me out?</p>