one line command to check file existence and FTP it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting one line command to check file existence and FTP it
# 1  
Old 05-11-2009
one line command to check file existence and FTP it

Hi all,
I need a batch script to Check for existence of file say i check for files with extension xml.done in C:\Myfile.(This folder contains .xml file and its corresponding .done files)
If the .done file exists then it should FTP the corresponding .xml file to UNIX.
Is this possible to do without creating a filelist?

regards,
Coddy.
# 2  
Old 05-11-2009
Code:
HOST='domain.com'
USER='yourid'
PASSWD='yourpw'

for file in *.done
do 
xmlfile=${file%.*}.xml
ftp -n $HOST <<END
quote USER $USER
quote PASS $PASSWD
put $xmlfile
quit
END
done


cheers,
Devaraj Takhellambam
# 3  
Old 05-11-2009
Quote:
Originally Posted by Codesearcher
Hi all,
I need a batch script to Check for existence of file say i check for files with extension xml.done in C:\Myfile.(This folder contains .xml file and its corresponding .done files)
If the .done file exists then it should FTP the corresponding .xml file to UNIX.
Is this possible to do without creating a filelist?

regards,
Coddy.
you are using cygwin? or are you referring to a pure batch file on windows?
# 4  
Old 05-12-2009
Its fully batch file on windows..

Regards,
Coddy
# 5  
Old 05-12-2009
Here is a skeleton batch script to create a file list if DONE files exist.
The script exits if there are no files.

Code:
@echo off
REM IF_TEST.BAT
CD C:\MYFILE
IF EXIST DIRLIST.TXT ERASE DIRLIST.TXT
REM Create list of files if there are any
IF EXIST *.DON DIR *.DON /B > DIRLIST.TXT
REM Exit script if no files found
IF NOT EXIST DIRLIST.TXT ECHO No DONE files found
IF NOT EXIST DIRLIST.TXT EXIT /B
REM Read back files list
TYPE DIRLIST.TXT

Providing that there is a simple relationship between the filenames,
converting the file extension can be done with the FOR command (see FOR /?).

Last edited by methyl; 05-12-2009 at 09:04 AM.. Reason: FOR comment
# 6  
Old 05-12-2009
Hey is there any option to FTP the files from Windows to UNIX without creating a filelist ??
A single line command is preferable..
Regards,
Coddy.
# 7  
Old 05-12-2009
no. the native FTP client from windows just cannot cut it. use a better FTP client, or code your ftp commands in the batch itself, echoing them to ftplist, then remove ftplist when finished.
OR, use another programming language that supports the FTP protocol, eg Perl or Python.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File existence check

hi i wanted to check if the file exist or not(multiple files) DIRE=/home/V478 if ; then echo "file present" else echo "file not present" fi But i am getting the error as : [: unexpected operator/operand (3 Replies)
Discussion started by: ATWC
3 Replies

2. Shell Programming and Scripting

How to check line existence in shell ?

Hi, We have some config file and there we are looking to append a line if it is not found. abc.conf authpriv.* /var/log/secure mail.* -/var/log/maillog *.debug @vxhgt-hskhng02 cron.* ... (12 Replies)
Discussion started by: Litu19
12 Replies

3. UNIX for Dummies Questions & Answers

To check for existence of a file

I need to check for the existence of a file *.log in a specific directory using a perl script. Presently am not in that particular directory. So i am using chdir ("/path/to/my/file) And then i am using the -e in an if statement to check if it exists. if (-e $File) {......} $File contains the... (1 Reply)
Discussion started by: manutd
1 Replies

4. Shell Programming and Scripting

command to check existence of file name which has regex

Hi All. Pls help me with the command to check existence of files (I'll mention name of the file as regex) and proceed with my further processing if atleast one of them exists in detail, I've a dir /tmp/TURP, which may or may not have files named with "exter*.txt" I need to check and... (2 Replies)
Discussion started by: skpvalvekar
2 Replies

5. Shell Programming and Scripting

Check for file existence using wildcards

I am using the following command to check for files on a Unix (Solaris 9) and on Linux: if (-r *.) then echo " las file found" else echo " no las file found" endif If no las file is present, the "no las file found" message is displayed. If a las file is present, however, I get... (9 Replies)
Discussion started by: phudgens
9 Replies

6. Shell Programming and Scripting

How to check for file existence?

i want to check if the file is in the directory or not, and also it should be handle error conditions, like missing files and report the error and exit. i did something like this: file ="hello" if !test -e "${file}" then echo "No such files exist!" exit 1 else do something....... fi ... (1 Reply)
Discussion started by: mingming88
1 Replies

7. AIX

Check for File Existence

I have requirement where i need to search for files which start with SALESORDER and PURCHASEORDER. i need to process the files with SALESORDER first and then PURCHASEORDER. If SALESORDER files are not there i dont want to process PURCHASEORDER and i want to come out of script. I have written a code... (4 Replies)
Discussion started by: dsdev_123
4 Replies

8. AIX

check for file existence

Hello I am having a requirement like if there is no file in the directory then i need a message to pop on after the execution of the script. My script basically does for File in `ls -t $DIRECTORY | tail -1`; if there is no file the DIRECTORY then the script is simply exiting with out... (2 Replies)
Discussion started by: dsdev_123
2 Replies

9. AIX

how to check the existence of a file during ftp using korn shell?

i can able to transfer a file from build server(AIX)to webserver using ksh through ftp.my query is to check the existence of file while transfering from one server to other .i.e i need some command or script that checks the existence of file with same name in both server,within ftp syntax. ... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

10. Shell Programming and Scripting

Csh to check for existence of file

Hi, I would like to check the existence of files (doesn;t matter the number of files) in a directory. My file is named in the following manner (always ending with " myfile "). Can anybody give me some guidance? EG: abc1_myfile sdfr_myfile sffgd_myfile and so on ...... My... (9 Replies)
Discussion started by: Raynon
9 Replies
Login or Register to Ask a Question