WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System_Net
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

DownloadFile

 Keywords:  DownloadFile FTP Get FTPGet System.Net System.Net.WebClient System.Net.CredentialCache System.Uri

;***************************************************************************
;**   FTP - Downloads the resource with the specified URI to a local file.
;**
;** Purpose:  Downloads the resource with the specified URI to a local file.
;** Inputs:  FTP filepath, local filepath, userid and password
;** Outputs: 
;** Reference: 
;**       REQUIRES WinBatch 2013A or newer & CLR version 4.0 
;**
;** Developer: Stan LittleField, Deana Falk 2013.06.24
;*************************************************************************** 
If Version( )< '2013A' 
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit 
EndIf

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; mscorlib assembly is automatically loaded by WinBatch when the CLR is loaded.
; ObjectClrOption ('use','mscorlib, version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
ObjectClrOption( 'use', 'System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' )

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Prompt for input
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strLocalFile = DirScript():'vCheck.zip'
strFtpFile = 'ftp://ftp.winbatch.com/wwwftp/wb01/vCheck.zip'
;strUser = ''
;strPswd = ''

If FileExist( strLocalFile ) Then FileDelete( strLocalFile )

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Create a class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oWeb = ObjectClrNew( 'System.Net.WebClient' )
oCache = ObjectClrNew( 'System.Net.CredentialCache')
oURI =  ObjectClrNew( 'System.Uri', strFtpFile )

; Add Credentials ( if necessary )
If isDefined(strUser) && isDefined(strPswd)
   oCred = ObjectClrNew( 'System.Net.NetworkCredential', strUser, strPswd )
   oCache.Add( oURI, 'Basic', oCred )
   oWeb.Credentials = oCache
Endif

; Download file
oWeb.DownloadFile( strFtpFile, strLocalFile ) 
          
If FileExist( strLocalFile ) Then Message( 'Success', 'File Downloaded: ' : strLocalFile)
Exit

Article ID:   W17832
Filename:   DownloadFile.txt
File Created: 2013:06:24:09:10:52
Last Updated: 2013:06:24:09:10:52