Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'FTP Upload
- 'Upload a file/folder to an FTP server
- 'I want to change this to the SFTP server==> how should I update this following script?? Any Idea Please I'am New In VBScript
- Set oShell = CreateObject("Shell.Application")
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- 'MsgBox "hello" && date
- Dim objFSO
- Varnow = now
- vardate = Day(varnow) & "-" & Month(varnow) & "-" & Year(varnow) & ".csv"
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- strFile = "D:/file.csv"
- strRename = "D:/file-" & vardate
- If objFSO.FileExists(strFile) Then
- objFSO.MoveFile strFile, strRename
- End If
- 'Set FSO = Nothing
- 'Path to file or folder to upload
- path = strRename
- FTPUpload(path)
- Sub FTPUpload(path)
- On Error Resume Next
- 'Copy Options: 16 = Yes to All
- Const copyType = 16
- 'FTP Wait Time in ms
- waitTime = 8000
- FTPUser = "ftuser"
- FTPPass = "psw"
- FTPHost = "hostname"
- FTPDir = "/Dir"
- 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)
- REM Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
- objFTP.CopyHere objItem,copyType
- End If
- 'Upload all files in folder
- REM If objFSO.FolderExists(path) Then
- REM 'Code below can be used to upload entire folder
- REM Set objFolder = oShell.NameSpace(path)
- REM Wscript.Echo "Uploading folder " & path & " to " & strFTP
- REM objFTP.CopyHere objFolder.Items, copyType
- REM End If
- If Err.Number <> 0 Then
- Wscript.Echo "Error: " & Err.Description
- End If
- 'Wait for upload
- WScript.Sleep waitTime
- If objFSO.FileExists(strRename) Then
- objFSO.MoveFile strRename, strFile
- End If
- End Sub
Add Comment
Please, Sign In to add comment