I am having a folder on ftp say employee, and this folder contains multiple .xlsx files. I need an excel vbs script to download all files of this folder to a folder on my pc. Please provide a script and some insite on how the script works.
Thanks D Ace
So far I have been to the below script with online help. I can download one specified file, hard coded in the script (myURL = "http://MYSERVERADDRESS/FILE_STATUS_1.xlsx "), by writing it to predefined file in script (oStream.SaveToFile "D:\test.xlsx"). However as per my requirement I want to download all files (like *.xlsx) of server folder to the local hard drive location as mentioned in the script. I am thinking of looping through the folder and then get files to local hard drive but the logic is just not clicking in my mind. Please help.
Option Explicit
Sub FileDownloadScript()
Dim myURL As String, sFilename As String
myURL = "http://MYSERVERADDRESS/FILE_STATUS_1.xlsx "
Dim WinHttpReq As Object, oStream As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "my user name", "my password"
WinHttpReq.Send
myURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile "D:\test.xlsx", 1
oStream.Close
End If
End Sub
Aucun commentaire:
Enregistrer un commentaire