FTP使用FileMaker或Applescript下载最新文件
我目前使用inserturl从外部FTP位置下载某些文件,我使用以下curl选项成功地实现了这一点 --用户“&$usr&”:“&$pw&”-o Stock Summary.csv” 这就像希望的那样,可以从FTP下载文件,但是,提供这些文件的公司可以说已经“移动了门柱” 不管出于什么原因,他们现在给这个文件加上前缀和后缀随机数,所以我需要调整它,以获得这个文件的最新版本,现在看起来像这样- 7818023-库存汇总表-035831FTP使用FileMaker或Applescript下载最新文件,ftp,applescript,filemaker,Ftp,Applescript,Filemaker,我目前使用inserturl从外部FTP位置下载某些文件,我使用以下curl选项成功地实现了这一点 --用户“&$usr&”:“&$pw&”-o Stock Summary.csv” 这就像希望的那样,可以从FTP下载文件,但是,提供这些文件的公司可以说已经“移动了门柱” 不管出于什么原因,他们现在给这个文件加上前缀和后缀随机数,所以我需要调整它,以获得这个文件的最新版本,现在看起来像这样- 7818023-库存汇总表-035831 任何建议或不同的方法都将不胜感激,因为我只是一个试图帮助家庭朋
任何建议或不同的方法都将不胜感激,因为我只是一个试图帮助家庭朋友的新手。如果您想从新文件标识符中提取“股票摘要”,那么这将实现:
on StripNumbers(FileLong)
set x to offset of "-" in FileLong
set temp to characters (x + 1) thru -1 of FileLong as string
set x to offset of "-" in temp
set temp to characters 1 thru (x - 1) of temp as string
return temp
end StripNumbers
on run
set FileLong to "7818023-Stock_Summary-035831"
set FileShort to my StripNumbers(FileLong)
end run
然后,您可以添加扩展名并运行FTP脚本。如果您希望从新文件标识符中提取“股票摘要”,则这将执行以下操作:
on StripNumbers(FileLong)
set x to offset of "-" in FileLong
set temp to characters (x + 1) thru -1 of FileLong as string
set x to offset of "-" in temp
set temp to characters 1 thru (x - 1) of temp as string
return temp
end StripNumbers
on run
set FileLong to "7818023-Stock_Summary-035831"
set FileShort to my StripNumbers(FileLong)
end run
然后,您可以添加扩展名并运行FTP脚本。查看前面的答案 特别是这一系列的狂欢,
curl --user <<USERNAME>>:<<PASSWORD>> ftp://<<SERVERURL>> 2>/dev/null | grep "Stock_Summary" | awk -F\ '{print $9}' | sort -n -t- -k3,4 -k1,2 -k2,2 | tail -1
注意:删除并填充>之间的所有内容
在AppleScript中,这可能看起来像:
on GetFileNameToPull(server, username, password, filePattern)
set theScriptToRun to "curl --user " & username & ":" & password & " ftp://" & server & " 2>/dev/null | grep '" & filePattern & "' | awk -F\\ '{print $9}' | sort -n -t- -k3,4 -k1,2 -k2,2 | tail -1"
set theFileName to do shell script theScriptToRun
return theFileName
end GetFileNameToPull
on GetFileNameFromFTPServer(server, username, password, remoteFileName, localFileName)
set theScriptToRun to "curl --silent --show-error --user " & username & ":" & password & " ftp://" & server & "/" & remoteFileName & " -o " & localFileName
do shell script theScriptToRun
end GetFileNameFromFTPServer
on run
set username to "USERNAME"
set thePassword to "PASSWORD"
set server to "SERVERNAME"
set pathToDownload to "/path/to/download/to"
set theRemoteFileName to GetFileNameToPull(server, username, thePassword, "Stock_Summary")
set theLocalFileName to pathToDownload & "/" & theRemoteFileName
GetFileNameFromFTPServer(server, username, thePassword, theRemoteFileName, theLocalFileName)
end run
查看前面的答案 特别是这一系列的狂欢,
curl --user <<USERNAME>>:<<PASSWORD>> ftp://<<SERVERURL>> 2>/dev/null | grep "Stock_Summary" | awk -F\ '{print $9}' | sort -n -t- -k3,4 -k1,2 -k2,2 | tail -1
注意:删除并填充>之间的所有内容
在AppleScript中,这可能看起来像:
on GetFileNameToPull(server, username, password, filePattern)
set theScriptToRun to "curl --user " & username & ":" & password & " ftp://" & server & " 2>/dev/null | grep '" & filePattern & "' | awk -F\\ '{print $9}' | sort -n -t- -k3,4 -k1,2 -k2,2 | tail -1"
set theFileName to do shell script theScriptToRun
return theFileName
end GetFileNameToPull
on GetFileNameFromFTPServer(server, username, password, remoteFileName, localFileName)
set theScriptToRun to "curl --silent --show-error --user " & username & ":" & password & " ftp://" & server & "/" & remoteFileName & " -o " & localFileName
do shell script theScriptToRun
end GetFileNameFromFTPServer
on run
set username to "USERNAME"
set thePassword to "PASSWORD"
set server to "SERVERNAME"
set pathToDownload to "/path/to/download/to"
set theRemoteFileName to GetFileNameToPull(server, username, thePassword, "Stock_Summary")
set theLocalFileName to pathToDownload & "/" & theRemoteFileName
GetFileNameFromFTPServer(server, username, thePassword, theRemoteFileName, theLocalFileName)
end run
我很抱歉如果我听起来很愚蠢,我真的对Applescripts一无所知,我甚至连操作Mac都不会,更不用说写完整的脚本了哈哈!FTP字符串会在这里合并到哪里?我很抱歉如果我听起来很愚蠢,我真的对Applescripts一无所知,我甚至连操作Mac都不会,更不用说写完整的脚本了ts哈哈!FTP字符串将在这里合并到哪里?