Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

Sample Windows 2008 batch script : test status of files transfer & retransfer if status fails

In one new project, our Win 2008 (client) ftp scripts had been failing
intermittently & the network chaps can't isolate where on the
network is the 'disconnect' happening.  Sometimes, files at the
remote ftp server end are locked or not there yet (ie apps at remote
end delayed by a couple of minutes in  creating the data file).

In ncftp, there are various status codes that we can test for:
These are the errorlevel values returned by ncftpget:

    ncftpget returns the following exit values:

       0. Success.
       1. Could not connect to remote host.
       2. Could not connect to remote host - timed out.
       3. Transfer failed.
       4. Transfer failed - timed out.
       5. Directory change failed.
       6. Directory change failed - timed out.
       7. Malformed URL.
       8. Usage error.
       9. Error in login configuration file.
      10. Library initialization failed.
      11. Session initialization failed.

My customer does not allow us to use opensource tools but
only Windows native ftp client, thus I'll a way to test if a
file get (or mget)'s status & if it fails, to pause for 10 mins
(doing 'ping localhost -n 600 > nul' would do as 1 ping is
abt 1 sec) & attempt retransfer again & if it fails attempt
again a 3rd time.

Will need some sample Windows batch script as I don't
quite know the syntax to check the %errorlevel% for
ftp.
SOLUTION
Avatar of arnold
arnold
Flag of United States of America 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
ASKER CERTIFIED SOLUTION
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
Avatar of sunhux
sunhux

ASKER

Bear with me as I'm totally new to PowerShell:

"Import-Module psftp" : does this mean this uses psftp or it's ftp?

Does Win 2003 Enterprise (32bit) comes with PowerShell?
Avatar of sunhux

ASKER

Btw, how do I execute the Powershell script?

Can it do the equivalent of ftp 'mget' ?
To get the control you want in determining what is going on, relying on a script provides you with a larger level of control.

powershell is available depending on whether you deployed it using WSUS or installed it as part of a windows update.

powershell get-help

Are you familiar with vbscript or c#?
SOLUTION
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