Get the latest file from a remote server from an FTP in Unix

前端 未结 1 1693
囚心锁ツ
囚心锁ツ 2020-12-11 11:08

I need to get a file from a remote host in Unix. I am using the ftp command. The issue is I need the latest file from that location. This is how I am doing it:<

1条回答
  •  离开以前
    2020-12-11 12:04

    You cannot use shell features, like aliases, piping, variables, etc, in ftp command script.

    The ftp does not support such advanced features using any syntax.

    Though, you can do it two-step (to make use of shell features between the steps).

    First get a listing of remote directory to a local file (/tmp/listing.txt):

    ftp -nv <

    Find the latest file:

    latest_file=`tail -1 /tmp/listing.txt`
    

    And download it:

    ftp -nv <

    0 讨论(0)
提交回复
热议问题