Solved

How FTP command do I use to tell a Dos Batch if a file exists or not on the server?

Posted on 2009-05-18
9
1,714 Views
Last Modified: 2013-11-29
Hi,
I am looking for a few commands for FTP.
I know how to Get, Put, and Delete, on an FTP Server, but How do I "check" for the existence of a file on it?

Here is what I want to do, and have most of it. In theory:
FTP login
Ftp Check for File,
If exists on server:
-->  get file
-->   Run as400 (our midrange computer) command
-->   delete file
if not exist
 -->   tell user
quit

Any help appreciated :) Thanks.
Rj
0
Comment
Question by:RjCoats
  • 5
  • 4
9 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 24413333
In FTP you cannot
- check for existence of files. A get on a non-existent file will create a empty file (0 bytes) with AS400 (this happens to me). That means you will have to (FTP) get the file, and (DOS) check its file size, then continue in FTP or send message.

ftp -s:getfile.ftp

for %%F in (theFile.xxx) do if %%~sF GTR 0 (

  ftp -s:doWhatever_and_Delete.ftp

) else (

  msg * File does not exist /t:5

)

Open in new window

0
 

Author Comment

by:RjCoats
ID: 24413612
If I want to do multiple commands in the "for do if" command, (where you have the ftp command to delete)
How is that done. This type of loop in a dos batch is new for me.
Thanks for your help so far. You have me headed the right way.
rj
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24413757
Between the brackets pair of the IF, you can add as many (DOS) commands as you like.

if 1 GTR 2 (
   echo Do one
   echo Do another
) else (
   echo Do nothing
   echo repeat the same
)

0
 

Author Comment

by:RjCoats
ID: 24414117
Thanks again, your gonna get some points outa me..
I have this command in my batch file...
FTP -n -i -d -s:jjorder.dat ftp.mydomain.com
Then my if this and that.
at the end of the ftp comman, the batch file just ends, it dont continue.

In the dat file I have
myusername
mypass
bin
get myfile.csv
quit

What am I doing wrong? I know when i execute another batch or exe file, i have to use call for it to come back.
Im kindof a novice at the command line FTP
Thanks again Olemo.
Rj
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 68

Expert Comment

by:Qlemo
ID: 24414287
I cannot see any reason for this. Does it echo your batch and FTP commands?
0
 

Author Comment

by:RjCoats
ID: 24414449
CLS
CD\JJ ONLINE ORDERS
\util\choice GET NEW ORDERS NOW?
IF ERRORLEVEL 2 GOTO NOLOAD

ftp -n -i -d -s:jjorder1.dat ftp.mydomain.com
PAUSE    <---- IT GETS TO HERE AND ECHO'S THE FTP, I ACTUALLY DO GET IT.
                          I HIT ENTER ON THE PAUSE, AND IT QUITS ON ME.

for %%F in JJORD.CSV do if %%~sF GTR 0 (
pause
@echo GOT NEW ORDERS
PAUSE
ftp  -n -i -d -s:jjorder2.dat ftp.MYdomain.com
PAUSe
@ECHO DELETED FILE
PAUSE
)
else (
@ECHO NO ORDERS ON WEB
PAUSE
 )

:NOLOAD
PAUSE
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 24414520
Syntax error in the FOR. Use:

for %%F in (JJORD.CSV) do if %%~sF GTR 0 (
0
 

Author Comment

by:RjCoats
ID: 24414554
WOOPS. one thing I did wrong, now it appears to work better, let me put those parenthisis back around the file name.
I thought it was an "example" but its part of the syntax.

0
 

Author Closing Comment

by:RjCoats
ID: 31582627
very good if I'd follow the instrcutions :) Thanks Olemo
0

Featured Post

New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Nexus OS - OSPF Command 3 49
network copying issue 4 60
Can't remote with RDC through ASUS RT-N66W Router 3 54
ssh setup on Cisco swith 11 42
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now