在Unix中从FTP获取远程服务器的最新文件 [英] Get the latest file from a remote server from an FTP in Unix
问题描述
我需要从Unix的远程主机获取文件。我正在使用 ftp
命令。问题是我需要该位置的最新文件。这是我如何做:
dir = / home / user / nyfolders
latest_file = $(ls * abc.123。* | tail -1)
ftp -nv open $ hostname
user $ username $ password
binary
cd $ dir
get $ latest_file
bye
EOF
但是我得到这个错误:
(远程文件)用法:get remote-file [local-file]
我想我试图从 ftp
命令中获取文件的方式是不正确的,有人可以帮我吗?
你不能使用shell特性,如别名,管道,变量等,在 ftp
命令脚本中。
ftp
支持使用任何语法的这些高级功能。
尽管如此,您可以分两步进行操作(在步骤之间使用shell功能)。
$ b
首先获取远程目录的列表到本地文件() /tmp/listing.txt
):
ftp -nv 打开$主机名
用户$用户名$密码
cd $ dir
nlist * abc.123。* /tmp/listing.txt
bye
EOF
找到最新的档案:
latest_file =`tail -1 / tmp / listing.txt`
然后下载它:
ftp -nv 打开$主机名
用户$用户名$密码
二进制
cd $ dir
获得$ latest_file
再见
EOF
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:
dir=/home/user/nyfolders
latest_file=$(ls *abc.123.* | tail -1)
ftp -nv <<EOF
open $hostname
user $username $password
binary
cd $dir
get $latest_file
bye
EOF
But I get this error:
(remote-file) usage: get remote-file [ local-file ]
I think the way I am trying to get the file from within the ftp
command is incorrect, can someone please help me out?
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 <<EOF
open $hostname
user $username $password
cd $dir
nlist *abc.123.* /tmp/listing.txt
bye
EOF
Find the latest file:
latest_file=`tail -1 /tmp/listing.txt`
And download it:
ftp -nv <<EOF
open $hostname
user $username $password
binary
cd $dir
get $latest_file
bye
EOF
这篇关于在Unix中从FTP获取远程服务器的最新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!