Note that this will take the last file alphabetically that begins with myfile. You could substitute any other filter and/or use other logic to sort the list.
spinel:/u02/sct/banner/bandev2/xxxxx/shl$ sh idoc_ftp_finaid.shl 'DEV2'
idoc_ftp_finaid.shl[39]: cd N:\orgs\"Financial Aid"\"CSSIDOCLoad" : not found
idoc_ftp_finaid.shl[40]: $(ls -rt | tail -1): not found
I changed the real name for xxxx
Again I have files in that directory that are like 3526_419184.dat 3526_ is is a constant
but the rest like 419184 are different I want to capture the last file that was move to that directory in UpLoadFileName, so I can FTP later
here is the rest of the code
# Initiate the FTP process
# Loop through remaining parameters to create ftp commands.
(
# Enter user-name and password in host machine
echo "user $RemoteUser $RemotePass"
# Set transfer mode
echo $TMode
# Change directory in remote machine
echo ${CDRemoteDir}
# Change local directory in local machine
### echo lcd $LocalDir
# Transfer file
echo get $UpLoadFileName
# End ftp session
echo quit
) | ftp -vin $RemoteHost >>${LF1} 2>>${LF2}
# End of FTP Process
if test $? -eq 0
then
echo "Successfully executed FTP" >>${LF1} 2>>${LF2}
else
echo "Error: could not execute FTP" >>${LF1} 2>>${LF2}
echo " " >>${LF1} 2>>${LF2}
echo "Script Ended." >>${LF1} 2>>${LF2}
exit 1
fi
1) Do you only have ftp access to the remote "Windows" machine?
Please bear in mind that the ftp is not shell and that the command set is very limited. Some ftp commands are quite similar to basic shell commands.
2) What exact version of Windows is involved? Please be very precise.
3) Is this a M$ ftp server or something else?
4) Do you you have administrator access to the Windows system to a level where you could set global environment variables? I ask this because it is notoriously difficult to get a M$ Windows system to display a DIR listing in a predicatable manner through ftp without setting a DIRCMD environment variable (see "help DIR"). Even then large directories may be displayed out of order due to underlying limitations of M$ code.
5) Your examples make it clear that the file timestamp is the only way of finding the most recent file. Your example directory when sorted by filename comes out in a different order from when sorted by file timestamp.
6) Footnote: If this is an application under development it is well worth considering including a sortable numeric timestamp in the filename (yyyymmddhhmmssfff).