shell脚本从FTP下载最新的文件 [英] shell script to download latest file from FTP

查看:425
本文介绍了shell脚本从FTP下载最新的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写shell脚本,我想从FTP下载最新的创建文件。
我想下载特定文件夹的最新文件。以下是我的代码。但它正在下载不是最新文件夹的所有文件。

  ftp -in ftp.abc.com<<<< ; SCRIPTEND 
用户xyz xyz
二进制
cd Rpts /
mget ls -t -r | tail -n 1
quit
SCRIPTEND

请帮我解决这个问题吗?

解决方案

尝试使用wget或lftp实用程序,它比较文件时间/日期和AFAIR,其目的是ftp脚本。如果可能的话,切换到ssh / rsync,你可以在这里阅读一下关于lftp而不是rsync:

https://serverfault.com/questions/24622/how-to-use-rsync-over-ftp



可能最简单的方法是将服务器端的最新版本链接到当前,并始终指向文件。如果你不是服务器的管理员,你需要用日期/时间列出所有文件,获取信息,解析它,确定哪一个是最新的,同时服务器上的状态可以改变,并且你发现自己处于更多状态复杂的解决方案比它的价值。



问题是,ls以某种方式对输出进行排序,时间可能不是默认值。有开关可以对它进行排序,例如基于修改时间,但即使服务器在ls -t上使用OK进行响应,您也无法确定它是否真的支持排序,它可以忽略所有开关并始终返回相同的列表,这就是为什么管理员通常使用当前链接(ln -s)。如果没有当前,为了确保你有正确的文件,无论如何你需要解析列表(ls -al)。

http://www.catb.org/esr/writings/unix-koans/shell-tools .html


I am writing shell script first time, I want to download latest create file from FTP. I want to download latest file of specific folder. Below is my code for that. But it is downloading all the files of the folder not the latest one.

ftp -in ftp.abc.com << SCRIPTEND
user xyz xyz
binary
cd Rpts/
mget ls -t -r | tail -n 1
quit
SCRIPTEND

help me with this, please?

解决方案

Try using wget or lftp utility instead, it compares file time/date and AFAIR its purpose is ftp scripting. Switch to ssh/rsync if possible, you can read a bit about lftp instead of rsync here:

https://serverfault.com/questions/24622/how-to-use-rsync-over-ftp

Probably the easiest way is to link last version on server side to "current", and always get the file pointed. If you're not admin of the server, you need to list all files with date/time, grab the information, parse it, decide which one is newest, in the meantime state on the server can change, and you find yourself in more complicated solution than it's worth.

The point is, that "ls" sorts output in some way, and time may not be default. There are switches to sort it e.g. base on modification time, however even when server responds with OK on ls -t , you can't be sure it really supports sorting, it can just ignore all switches and always return the same list, that's why admins usually use "current" link (ln -s). If there's no "current", to make sure you have the right file, you need to parse list anyway ( ls -al ).

http://www.catb.org/esr/writings/unix-koans/shell-tools.html

这篇关于shell脚本从FTP下载最新的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆