Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - How to Easily Use FTP in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

How to Easily Use FTP in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2007-09-04

    Table of Contents:
  • How to Easily Use FTP in WSH
  • Uploading and Downloading files
  • Extending the Chilkat FTP ActiveX control
  • Creating a Text File

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    How to Easily Use FTP in WSH - Extending the Chilkat FTP ActiveX control


    (Page 3 of 4 )

    As you begin using the Chilkat FTP control, you may find that you wish to take your scripts much farther than simple uploads and downloads. I want to take a few minutes and examine some other coding practices that you may find useful.

    One of these is checking for the existence of a file on the remote server. Perhaps you want to add some error-handling, or maybe you want to download an updated file only if it exists. In either case, checking for the existence of a file could prove useful.

    Function FileExists(rDir, rFile)

       objFtp.ChangeRemoteDir(rDir)

       strTemp = objFtp.Listpattern

       objFtp.ListPattern = rFile

       If objFtp.GetSize(0) = -1 Then

          FileExists = False

       Else

          FileExists = True

       End If

       objFtp.ListPattern = strTemp

    End Function

    This simple function makes use of the GetSize method to check whether a file exists. It returns the file’s size in bytes if found and returns –1 if not. So a simple If statement allows us to create a function that will return a Boolean value based on whether or not a file exists.

    Notice that I’ve changed the ListPattern value so that it only lists the file for which we are looking. Since this is a global setting, I’ve made sure to capture its entering value and reset it afterward.

    Now we’ll take a look at creating files and directories. Again, you will see a similar construct for these functions. Notice that the only real changes are the methods I’ve invoked to perform the action.

    Function CreateDirectory(rDir, rName)

       If objFtp.IsConnected Then

          success = objFtp.ChangeRemoteDir(rDir)

           If (success <> 1) Then

              CreateDirectory = objFtp.LastErrorText

              Exit Function

           End If

          success = objFtp.CreateRemoteDir(rName)

           If (success <> 1) Then

              CreateDirectory = objFtp.LastErrorText

              Exit Function

           End If

           

          CreateDirectory = "ok"

       End If

    End Function

    More Windows Scripting Articles
    More By Nilpo


       · In a follow-up to my "Using FTP in WSH" article, we will examine a much easier FTP...
     

    WINDOWS SCRIPTING ARTICLES

    - Adding Controls to an Application with WPF
    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway