Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp script - check if file exits

Status
Not open for further replies.

zalmanp

IS-IT--Management
Jun 13, 2003
19
0
0
US
I am running a .bat file that calls an ftp server and references the commands using a .txt file. Everything is working well.
My problem is when the built in windows FTP client tries to download a file from the ftp server using the get command, if the file does not exist on the server, it wipes out the file that is locally on my C: drive and leaves me with a blank file.

I must always keep the field headers in this file and as such I must make sure that if there is no file on the server to leave the one locally alone.

How can this be done?

(Is there a way to first look to see if the file exist and only then initiate the download?)

Need help - - - - - - Thanks!


 
In the batch file, rename the local file before calling ftp.


"We must fall back upon the old axiom that when all other contingencies fail, whatever remains, however improbable, must be the truth." - Sherlock Holmes

 
Thanks tfq13 for your post. Is there an "if" statement in the .bat which can check for an existing file on a unix server?

Thanks LawnBoy. How can I know if there was no file to ftp and therefore I woulod need to rename it back or there was a new file to download and therefore not to rename it back?

I hope my questions are clear. I really appreciate your help.

 
As long as the unix server has a file system the windows system can understand (and vice versa), this should not be a problem.

It sounds to me like you already have the windows systems talking/sharing files with the unix system. At this point, all you have to do is make sure that the file name in the "if" statment is exactly as it is named in the .bat.

If for some reason I am misunderstanding you, and you do not have the unix and windows systems talking/sharing files, I recommend you look at the below:


and


Which will assist in properly setting up the systems.
 
From an ancient DOS book:
Code:
IF NOT EXIST downloaded.file rename renamed.file original.file

IF EXIST and IF NOT EXIST do work in XP commands.


"We must fall back upon the old axiom that when all other contingencies fail, whatever remains, however improbable, must be the truth." - Sherlock Holmes

 
Thanks LawnBoy. How can I know if there was no file to ftp and therefore I woulod need to rename it back or there was a new file to download and therefore not to rename it back?
If you rename the original file before the download and the download is successful, the file will exist. So if you then try to rename the original file back to it's original file name, it will fail, and no harm done.



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top