# !bin/bash
# SomeConfigs
TOUCHFILE='/somepath/inYourLocal/someFilename.touch'
RemoteSFTPserverPath='/Remote/Server/path/toTheFiles'
LocalPath='/Local/Path/toReceiveTheFiles'
FTP_Server_UserName='someUser'
FTP_Server_Password='SomePassword'
ServerIP='//127.12.11.35'
# Transfer files from FTP Server #This is the main command
ftp_command="lftp -e 'mirror --only-missing --newer-than=${TOUCHFILE} --older-than=now-2minutes --parallel=4 --no-recursion --include "SomeFileName*.csv" ${RemoteSFTPserverPath}/ ${LocalPath}/;exit' -u ${FTP_Server_UserName},${FTP_Server_Password} sftp:${ServerIP}"
# CommandToexecute The Job
eval ${ftp_command}
# After finishing the lftp job You have to update the touch file for the next job
# This will update to current timestamp
touch /somepath/inYourLocal/someFilename.touch
# If you want to update with the last file received time
TchDate=$(stat -c %y "$(ls -1t ${LocalPath} | head -n1)" | date)
touch -d ${TchDate} /somepath/inYourLocal/someFilename.touch
# Stat on latest file in remote server #You can do this way also
TchDate=$(ssh -o StrictHostKeyChecking=no ${FTP_Server_UserName}@${FTP_Server_Password} "stat -c %y \"$(ls -1t ${RemoteSFTPserverPath}/ | head -n1)\" | date")
touch -d ${TchDate} /somepath/inYourLocal/someFilename.touch
# Once you have the files in your local you can copy them to hdfs
hdfs dfs -put -f /Local/Path/toReceiveTheFiles/*.csv /HDFS/PATH
# Remove the files in local so that you can accommodate for the upcoming files
rm -r -f /Local/Path/toReceiveTheFiles/*.csv
1条答案
按热度按时间ergxz8rk1#
您可以使用lftp作业中的touch文件来实现这一点,下面是我的解释和代码。查看每一步的评论。
在lftp工作中,你有很多选择
man lftp
会是你最好的来源