Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Ftp Connect And Upload
 

Vbscript / Web Servers / Ftp Connect And Upload

This script uses Windows to create an FTP connection to an FTP server and upload single or multiple files. Very useful for automating backups to an FTP server. 

'FTP Upload
'Upload a file/folder to an FTP server


Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Path to file or folder to upload
path = "test.txt"

FTPUpload(path)


Sub FTPUpload(path)

On Error Resume Next

'Copy Options: 16 = Yes to All
Const copyType = 16

'FTP Wait Time in ms
waitTime = 80000
 
FTPUser = "user"
FTPPass = "pass"
FTPHost = "
www.domain.com"
FTPDir = "/htdocs/"

strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)

'Make new folder on FTP site
'objFTP.NewFolder "FTP Backup"


'Upload single file      
If objFSO.FileExists(path) Then

Set objFile = objFSO.getFile(path)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)

Set objItem = objFolder.ParseName(objFile.Name)

Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
 objFTP.CopyHere objItem, copyType


End If

'Upload all files in folder
If objFSO.FolderExists(path) Then

'Code below can be used to upload entire folder
Set objFolder = oShell.NameSpace(path)

Wscript.Echo "Uploading folder " & path & " to " & strFTP
objFTP.CopyHere objFolder.Items, copyType

End If


If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If

'Wait for upload
WScript.Sleep waitTime

End Sub






Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers
          - Ftp Connect And Upload
          - Iis Create Website
          - Webpage Url Html Capture