Link to home
Start Free TrialLog in
Avatar of Rizuan
RizuanFlag for Malaysia

asked on

To run FTP in Windows XP

Please find attached is a ftp batch file that run on UNIX. Please help me to convert this batch so that it can run on Windows XP..
ftp-in-unix.txt
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Hi, we can help you but since the script is depending for a lot of specific Unix commands and paths I suggest you install Cygwin first on your Windows XP machine. What do you want to do with paths like this that are in the script:

log=/u01/app/airops/interface/SWIFT/logs/gateTransfer$date.log

errlog=/u01/app/airops/interface/SWIFT/logs/gateErr$date.err

FTPlist=/u01/app/airops/interface/SWIFT/logs/gateFTPlist.txt

templog=/u01/app/airops/interface/SWIFT/logs/gateStatlog.txt

inputDir=/u01/app/airops/interface/SWIFT/out/

archiveDir=/u01/app/airops/interface/SWIFT/Archive/

outputDir=/PROJECT_A/01_source_layer/01_raw_source_files/MASKEDS/

Let me know when you've installed Cygwin.
Avatar of Rizuan

ASKER

I probably not able to install Cygwin since my laptop is the company property. Basically what i want is windows batch file that able to ftp a file to a server.

First it will check whether the server is available or not. If yes go to the next step. If not, it will log the error.

The next step is to check whether the file is ready or not. If yes go to the next step. If not, it will log the error.

The 3rd step is to ftp the file to the server. If success, then move the file from the original folder to archive folder with date and time stamp.

If not, then log the error.

For more details, you can refer to the file that i have attached in my post.
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'd use this for ftp if you are happy with the built in ftp.exe client:
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting

The easiest method is #3 as it keeps it all in the same file.

I started writing up what you need but frankly there are loads of parts to it and would suggest maybe you should split it up... your unix file explains what needs doing OK but what you are asking for frankly is a bit much of a question here if you want a pre-written tested script, you are talking a good amount of time to do it justice IMO if you want it belt and braces checking like in the unix script.

You are looking at I guess:
PING server to check it is up
Login to ftp server as test that ftp server is there, and that FTP user works
Check the local files exist to transfer
Run ftp script to transfer them.... one, five, hundred?  Are they in the same dir, subdirs etc?
Check it transferred OK
Get date into correct format (
https://www.experts-exchange.com/articles/OS/Microsoft_Operating_Systems/MS_DOS/Using-dates-in-batch-files-scripts.html )
Use that date to move to archive area if transfer was OK.

Steve
Avatar of Rizuan

ASKER

gerwinjansen,

Sorry for the late response. Actually i have tried the first checking which is to check the server availability but i don't understand why errorlevel is not working. No matter whether the condition is false or true, it keep on telling that FTP server unavailable in ftplog.txt.
Unless this is on Windows 2000 (which didn't give an errorlevel from PING) then if the PING fails it will give errorlevel 1, otherwise errorlevel 1

You could also do:

rem 1 - Check availability
ping -n 1 x.x.x.x >nul 2>nul || goto FTP_UNAV

etc.

But like I said there are quite a few parts to your Q so probably best to concentrate on few bits at a time IMO.

Steve
I agree with dragon-it, work on 1 thing at a time.

Try the ping and echo command first from a command prompt:
ping <ftp server>
echo %ERRORLEVEL%

Open in new window


Sample output below, please post your output.

ping ftp.google.com
Ping request could not find host ftp.google.com. Please check the name and try again.

echo %ERRORLEVEL%
1

ping nas

Pinging nas [123.123.123.123] with 32 bytes of data:
Reply from 123.123.123.123: bytes=32 time=3ms TTL=64
Reply from 123.123.123.123: bytes=32 time=2ms TTL=64
Reply from 123.123.123.123: bytes=32 time=2ms TTL=64
Reply from 123.123.123.123: bytes=32 time=1ms TTL=64

Ping statistics for 123.123.123.123:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 3ms, Average = 2ms

echo %ERRORLEVEL%
0
As an example.... no matter what I PING by name I always get an answer... I use OpenDNS here and it responds with one of their server IP's to redirect browser to "friendly" page by default.  Side effect is PING xyzsa gives "OK".  PING of bad IP fails still of course.

So please try as suggested above, lets find that then part 2 etc.  If it comes to it maybe as second or more relatede questions because then other people pick them up too.