capture the last file when you don't know the all name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting capture the last file when you don't know the all name
# 1  
Old 05-25-2009
capture the last file when you don't know the all name

I have to ftp a file from a directory in Windows, I need to be able to ftp the last file that was put in the directory, the only thing I know about that file is that the 4 first digits are always the same (3520) then it is a _5(more digits), random digits, so it will be something like this 3520_20401. There are other files in that directory, I just care about the ones that start with 3520

I have a script like this one (part of the script) tah works well when I know the name of the file,

Someone told me that those commands will work in UNIX BUT I need to do it in windows (DOS):
ls -rt 3256 | tail -1 | read lastfile
lastfile=$(ls -rt 3256 | tail -1 )
what will be the equivalent of the command in DOS
# Change directory in remote machine
echo $RemoteDir
Then How can I capture the last file…
here??


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 $RemoteDir
# 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

Thank you SO much for any hint
# 2  
Old 05-25-2009
those commands should work if you have things like cygwin etc, but no, DOS does not have ls or tail etc...If you want to use those tools, you can try downloading them here. Alternatively, you can use programming languages like Perl or Python which comes with FTP modules for easier FTP control. an example with Python
Code:
import os
import ftplib
DIR=os.path.join("c:\\","path1","path2") #current directory
os.chdir(DIR)
temp=0
d={}
FILE=""
for files in os.listdir(DIR):
    TIME=os.path.getmtime(files)
    if TIME > temp:
        temp=TIME
        FILE=files        
# Ftp information. change as needed
server="localhost"
user="anonymous"
password="test@hotmail.com"

def upload(ftp, filename): 
    ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024)

def download(ftp, filename):    
    ftp.retrbinary("RETR " + filename, open(filename,"wb").write)
    
try:
    ftp = ftplib.FTP(server)    
    ftp.login(user,password)
    ftp.set_debuglevel(3)
except Exception,e:
    print e
else:    
    ftp.cwd("incoming")    
    download(ftp,"mytext.txt")
#  upload(ftp,FILe)


Last edited by ghostdog74; 05-25-2009 at 10:21 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Why I don't see the time in some file/directory?

Hi all, When doing an ls -l, why is it that I have the date and time on some of the files and directory, while others don't? :wall: Is there a way to show the date and time using a different command? OS is Linux and Solaris. Any response much appreciated. Thanks in advance. (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

Don't display file name

Hi I have a directory where i have 10 -12 files, i want to store word count in seperate file without any file name. i have written the logic which needs to be corrected filename.txt for i in /backup/temp/rajesh/12Apr2012_South *.LOG do #echo "File size of $i is" wc -l $i... (5 Replies)
Discussion started by: guddu_12
5 Replies

3. UNIX for Advanced & Expert Users

Don't find file from foxbase 2.1.2d

Hi there, finally i'm installed Sco Foxbase 2.1.2d over my Sco Open Server 5.0.7v server. Well at this point almost is working fine, but, when i Run mi application i receive the next error: "sh: the_name_of_file": does not exist". I checked it over the Hard Disk and the file exist, the... (1 Reply)
Discussion started by: danilosevilla
1 Replies

4. Shell Programming and Scripting

capture output of file and send last string thereof to new file

Hello, If I run a program from within shell, the output is displayed in the command line terminal. Is there a way I can capture that output and choose only the very last string in it to send it to a new file? Thank you (6 Replies)
Discussion started by: Lorna
6 Replies

5. Shell Programming and Scripting

Script to capture new lines in a file and copy it to new file

Hi All, I have a file that gives me new line/output every 5 minutes. I need to create a script that capture new line/output besides "IN CRON_STATUS", in this case the new output is "begin ------ cron_status.sh - -----------". I want this script to capture the line starting from "begin ------... (0 Replies)
Discussion started by: fara_aris
0 Replies

6. Shell Programming and Scripting

capture the file name

I am trying to capture the file name(which is not of fixed length) and put it in a variable. It is working in unix whereas when I am running the same script in Informatica it is not giving me the desired output. But when I comment the option(find the file name) then it is working fine. It can... (4 Replies)
Discussion started by: Mandab
4 Replies

7. Shell Programming and Scripting

lazy capture don't work (regexp in perl)

hello all im trying to capture only the first brackets but no matter what i do i keep capturing from the first brackets to the last one , here what i have : <% if (!Env.strLen(oidInvoice)); szDocumentTitle = Env.formatS("S",Env.getMsg("BP_INVOICE_ENUMERATION_CREATE_TITLE")) %> and... (1 Reply)
Discussion started by: umen
1 Replies

8. UNIX for Advanced & Expert Users

Capture Value from file

I have a file in the following Format Fundid: 100-BankA AccountNumber Balance 1 200 2 300 3 400 FundId:123321-BankB AccountNumber Balance 1 200 3 100 ........... I can have N number of funds. (1 Reply)
Discussion started by: kris01752
1 Replies

9. UNIX for Dummies Questions & Answers

Deleting a file I don't own

I have a directory with permissions set 777, and some gumby has dumped a bunch of files and directories in there. I don't own the culprit files or directories, but do own the containing directory - Is there some way I can delete this other user's files? The other interesting thing is that... (5 Replies)
Discussion started by: kumachan
5 Replies
Login or Register to Ask a Question