[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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
0
Rizuan
Asked:
Rizuan
  • 3
  • 3
  • 2
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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.
0
 
RizuanAuthor Commented:
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.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I would suggest that you use WinSCP in batch mode as an FTP client. You can use this client to setup your connection and then use the command line version to send your file. Checking the server can be done using 'ping', assuming that's what you mean by 'available'. What do you mean by 'whether the file is ready or not'? I don't understand this.

Here is a basic script, note that you have to build the ftpscript.txt file using the GUI first.
rem 1 - Check availability
ping -n 1 <ftp server> >nul 2>nul
if %ERRORLEVEL% NEQ 0 goto FTP_UNAV

rem 2 - Check file readiness
rem TBD - see question above

rem 3 - FTP file
winscp.exe /console /script=ftpscript.txt
if %ERRORLEVEL% NEQ 0 goto FTP_ERROR
echo FTP sending OK >> ftplog.txt
move <orig folder>\<file> <archive folder>/
goto END

:FTP_ERROR
echo FTP error sending file >> ftplog.txt
goto END

:FILE_UNAV
echo File not ready >> ftplog.txt
goto END

:FTP_UNAV
echo FTP server unavailable >> ftplog.txt

:END

Open in new window

0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
Steve KnightIT ConsultancyCommented:
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 (
http://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
0
 
RizuanAuthor Commented:
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.
0
 
Steve KnightIT ConsultancyCommented:
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
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
0
 
Steve KnightIT ConsultancyCommented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now