CuteFTP upload script (vbs)

Source: Internet
Author: User
Tags ftp site

Option explicit forces explicit declaration of variables.

'*************************************** *****************************
'*-=-
'* CuteFTP Pro script
'*-=-
'*
'* Author: Zhang Bo
'*
'Cuteftp script (VBScript), uploaded to multiple servers
'The newer versions of CuteFTP software must be installed first (major bugs exist in earlier versions, and version 6.0 is normal)
'When running the script, you may need to close the CuteFTP window first (this problem occurs in some versions)
'Content to be configured:
'Variable appname Application name, which is displayed during Script Execution
The 'variable localdir is used as the absolute local path for transit. It is automatically created if it does not exist.
'Array remoteinfo target server information, including domain name (IP), user, password, basic path
'Various properties of object mysite mysite2, CuteFTP object connecting source FTP and target FTP, You need to configure the site domain name or IP address, user name, password
'Array relative path and file name of the file to be transferred by jobinfo
'Relative path can be "" or multi-level directory "dir1/dir2"
'The file name can contain wildcards. Wildcards may be used together with sub-directories. UNIX hosts must be case sensitive.
'The task name is prompted for the first time during execution, the task to be executed is prompted for the second time (the task can be canceled at this time), the task is actually executed, and the task is finally prompted to be completed

'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''
'General Functions
'Change local working path
Function lchangedir (varte, vardir)
If "" = vardir then exit function
If (not (varte. localexists (vardir) then
Varte. createlocalfolder vardir
End if
Varte. localfolder = vardir
End Function
'Change the remote working path
Function rchangedir (varte, vardir)
Dim B
If "" = vardir then exit function
B = varte. remoteexists (vardir)
If (not cbool (B) then
Varte. createremotefolder vardir
End if
Varte. remotefolder = vardir
End Function
'Changing the local and remote working paths at the same time
Function lrchangedir (varte, lbasedir, rbasedir, lrdir)
Lchangedir varte, lbasedir
Lchangedir varte, lrdir
'Varte. remotecommand "cd"
Rchangedir varte, rbasedir
Rchangedir varte, lrdir
End Function

'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''
'Function of a specific application
Function addremoteinfo (infoarray, host, login, pass, basedir)
If infoarray (0, 0)> = ubound (infoarray) then
Msgbox "addremoteinfo: array fulled"
Quit 1
End if
Infoarray (0, 0) = infoarray (0, 0) + 1
 
Infoarray (0, 0), 0) = Host
Infoarray (0, 0), 1) = Login
Infoarray (0, 0), 2) = pass
Infoarray (0, 0), 3) = basedir
End Function
Function addjobinfo (infoarray, reldir, file)
If infoarray (0, 0)> = ubound (infoarray) then
Msgbox "addremoteinfo: array fulled"
Quit 1
End if
Infoarray (0, 0) = infoarray (0, 0
 
Infoarray (0, 0), 0) = reldir
Infoarray (0, 0), 1) = File
End Function
Function initteobj (teobj, infoarray, I)
Teobj. Protocol = "ftp"
Teobj. Host = infoarray (I, 0)
Teobj. login = infoarray (I, 1)
Teobj. Password = infoarray (I, 2)
Teobj. useproxy = "off"
Teobj. maxconnections = 5
Teobj. transfertype = "ASCII"
End Function

Dim appname' Application name
Dim report' report
Dim I, J' general cycle variable
Appname = "Provincial centralized file publishing"
Report = ""
Msgbox "CuteFTP Pro vbs script startup-" & appname

Dim mysite 'ftp site
Dim localdir 'local basic path must be an absolute path
'Create a CuteFTP object
Set mysite = Createobject ("cuteftppro. teconnection ")
 
'Subscript 0 indicates the number of valid data records.
Dim remoteinfo () 'array subscript is based on 0 and defines the maximum subscript. Therefore, it is available (0-, 0-3)
'The second dimension is based on the host name, Logon Name, password, and basic path. The first dimension 0 is not used.
Dim jobinfo (, 1) 'does not use 0 in the first dimension. The second dimension follows the relative path and file name.
Remoteinfo (0, 0) = 0
Jobinfo (0, 0) = 0
 
'Local basic path
Localdir = "local root directory" 'must be an absolute path
 
'Site information. Only one remote site can be added and multiple sites not tested can be added.
Addremoteinfo remoteinfo, "ip address", "User Name", "password", "remote root directory"

 

'Task info
'Addjobinfo jobinfo, "relative path", "file name, which can contain wildcards and Recursion"
'Addjobinfo jobinfo, "relative path", "file name, with wildcards"
'Addjobinfo jobinfo, "relative path", "file name, with wildcards"
'Addjobinfo jobinfo, "relative path", "file name, with wildcards"

Report = "the following tasks will be executed soon:" & CHR (13) & CHR (10)
For I = 1 to jobinfo (0, 0)
Report = Report & CHR (13) & CHR (10) & jobinfo (I, 0) & "-" & jobinfo (I, 1)
Next
Report = Report & CHR (13) & CHR (10) & CHR (13) & CHR (10) & "local path:" & CHR (13) & CHR (10) & localdir
Report = Report & CHR (13) & CHR (10) & "Purpose :"
For I = 1 to remoteinfo (0, 0)
Report = Report & CHR (13) & CHR (10) & remoteinfo (I, 0) & ":" & remoteinfo (I, 3)
Next
If vbcancel = msgbox (report, vbokcancel) then
Quit 1
End if

Report = ""
For I = 1 to remoteinfo (0, 0)
Initteobj mysite, remoteinfo, I
'Connect to the site
Mysite. Connect
If (not cbool (mysite. isconnected) then
Msgbox "cocould not connect to:" & mysite. Host & "aborting! "& Mysite. errordescription
Quit (1)
End if

For j = 1 to jobinfo (0, 0)
Lrchangedir mysite, localdir, remoteinfo (I, 3), jobinfo (J, 0)
Mysite. Upload jobinfo (J, 1)
Next
'Close the connection
Mysite. Close
Report = Report & CHR (13) & CHR (10) & remoteinfo (I, 0)
Next
 
Msgbox "CuteFTP Pro vbs script ended-" & appname & CHR (13) & CHR (10) & report
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.