Guest User

Untitled

a guest
Jan 11th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. 'FTP Upload
  2. 'Upload a file/folder to an FTP server
  3. 'I want to change this to the SFTP server==> how should I update this following script?? Any Idea Please I'am New In VBScript
  4.  
  5.  
  6. Set oShell = CreateObject("Shell.Application")
  7. Set objFSO = CreateObject("Scripting.FileSystemObject")
  8. 'MsgBox "hello" && date
  9. Dim objFSO
  10. Varnow = now
  11. vardate = Day(varnow) & "-" & Month(varnow) & "-" & Year(varnow) & ".csv"
  12. Set objFSO = CreateObject("Scripting.FileSystemObject")
  13. strFile = "D:/file.csv"
  14. strRename = "D:/file-" & vardate
  15. If objFSO.FileExists(strFile) Then
  16. objFSO.MoveFile strFile, strRename
  17. End If
  18.  
  19. 'Set FSO = Nothing
  20.  
  21.  
  22.  
  23. 'Path to file or folder to upload
  24. path = strRename
  25.  
  26. FTPUpload(path)
  27.  
  28.  
  29. Sub FTPUpload(path)
  30.  
  31. On Error Resume Next
  32.  
  33. 'Copy Options: 16 = Yes to All
  34. Const copyType = 16
  35.  
  36. 'FTP Wait Time in ms
  37. waitTime = 8000
  38.  
  39. FTPUser = "ftuser"
  40. FTPPass = "psw"
  41. FTPHost = "hostname"
  42. FTPDir = "/Dir"
  43.  
  44. strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir
  45. Set objFTP = oShell.NameSpace(strFTP)
  46.  
  47. 'Make new folder on FTP site
  48. 'objFTP.NewFolder "FTP Backup"
  49.  
  50.  
  51. 'Upload single file
  52. If objFSO.FileExists(path) Then
  53.  
  54. Set objFile = objFSO.getFile(path)
  55. strParent = objFile.ParentFolder
  56. Set objFolder = oShell.NameSpace(strParent)
  57.  
  58. Set objItem = objFolder.ParseName(objFile.Name)
  59.  
  60. REM Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
  61. objFTP.CopyHere objItem,copyType
  62.  
  63.  
  64. End If
  65.  
  66. 'Upload all files in folder
  67. REM If objFSO.FolderExists(path) Then
  68.  
  69. REM 'Code below can be used to upload entire folder
  70. REM Set objFolder = oShell.NameSpace(path)
  71.  
  72. REM Wscript.Echo "Uploading folder " & path & " to " & strFTP
  73. REM objFTP.CopyHere objFolder.Items, copyType
  74.  
  75. REM End If
  76.  
  77.  
  78. If Err.Number <> 0 Then
  79. Wscript.Echo "Error: " & Err.Description
  80. End If
  81.  
  82. 'Wait for upload
  83. WScript.Sleep waitTime
  84. If objFSO.FileExists(strRename) Then
  85. objFSO.MoveFile strRename, strFile
  86. End If
  87. End Sub
Add Comment
Please, Sign In to add comment