want script to upload download files from FTP - shell

hi friends can any one help me script to upload & download Data from FTP and if its possible to create a log report
thank you friends
i would be very thankful to you if help

This downloads http but also from ftp. It can upload at least http (never tried ftp), see the docs. To upload change the verb and file.send uploaddata.
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://www.pepperresources.org/LinkClick.aspx?fileticket=B1doLYYSaeY=&tabid=61", False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\test.txt", 2

Related

Unable to download the windows update using script

I am running Windows 2015 LTSB and use below script to download the Windows patches as and when required.
Previously the below script use to work from normal user, but from past few days it just shows the message as
Download completed successfully. Please press any key to continue.
Where actually nothing is downloaded and this script doesn't go to install updates.
And when I execute the same script from user with Admin privileges, it downloads and installs the relevant update packages.
I suspect that downloader.Download() is behaving differently for Admin and Normal user.
Can you please assist me in knowing what is the cause of updates not getting downloaded from normal user.
Option Explicit
Dim updateSession, updateSearcher, update, searchResult, downloader, updatesToDownload, updatesToInstall, installer, installationResult, InputKey, i, endKey
If Right((LCase(WScript.FullName)),11) <> "cscript.exe" Then
WScript.Echo "Please carry out this script using CSCRIPT.EXE." & _
vbCrLf & "Example: cscript WindowsUpdate.vbs"
WScript.StdOut.Write vbCrLf & "Please press any key to continue."
endKey = WScript.StdIn.ReadLine
WScript.Quit(0)
End If
Dim strInp
On Error Resume Next
WScript.Echo "Press Enter key to begin Windows Update."
strInp = WScript.StdIn.ReadLine
WScript.Echo "------------------------------"
WScript.Echo "Windows Update"
WScript.Echo "------------------------------"
WScript.Echo "Verifying latest update..."
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software' and AutoSelectOnWebSites=1")
'If Err.Number <> 0 Then
If IsNull(searchResult.Updates.Count) Or IsEmpty(searchResult.Updates.Count) Then
WScript.Echo "An error occurred. Please check your network connection and try again."
WScript.StdOut.Write vbCrLf & "Please press any key to continue."
endKey = WScript.StdIn.ReadLine
'Err.Clear
WScript.Quit(0)
End If
For i = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
WScript.Echo i + 1 & vbTab & update.Title & " Size: " & update.MaxDownloadSize
Next
If searchResult.Updates.Count = 0 Then
WScript.Echo "Windows is up to date."
WScript.StdOut.Write vbCrLf & "Please press any key to continue."
endKey = WScript.StdIn.ReadLine
WScript.Quit(0)
Else
WScript.Echo "A newer version of " & searchResult.Updates.Count & _
" is found. Downloading starts."
End If
WScript.StdOut.Write "Preparing download..."
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For i = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
WScript.StdOut.Write "."
updatesToDownload.Add(update)
Next
WScript.Echo vbCrLf & "Newer version of programs is downloading..."
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
'WScript.Echo "DEBUG [downloader.Download().ResultCode]:" & downloader.Download().ResultCode
If downloader.Download().ResultCode = 2 Then
WScript.Echo "Download completed successfully."
Else
WScript.Echo "Download failed."
End If
If downloader.Download().ResultCode = 4 Then
WScript.StdOut.Write vbCrLf & "Please press any key to continue."
endKey = WScript.StdIn.ReadLine
WScript.Quit(0)
End If
WScript.Echo "Download the following programs is successfully completed."
For i = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
If update.IsDownloaded Then
WScript.Echo i + 1 & vbTab & update.Title
End If
Next
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
WScript.StdOut.Write "Preparing installation..."
For i = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
If update.IsDownloaded = True Then
WScript.StdOut.Write "."
updatesToInstall.Add(update)
End If
Next
'WScript.StdOut.Write vbCrLf & "DEBUG [updatesToInstall.Count]:" & updatesToInstall.Count
If updatesToInstall.Count = 0 Then
WScript.Echo vbCrLf & "Installation failed."
WScript.StdOut.Write vbCrLf & "Please press any key to continue."
endKey = WScript.StdIn.ReadLine
WScript.Quit(0)
End If
WScript.Echo vbCrLf & "Installing..."
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
If installationResult.ResultCode = 2 Then
WScript.Echo "Installation completed successfully."
Else
WScript.Echo "Installation failed."
End If
WScript.Echo "Detail information."
For i = 0 to updatesToInstall.Count - 1
WScript.StdOut.Write i + 1 & vbTab & _
updatesToInstall.Item(i).Title
If installationResult.GetUpdateResult(i).ResultCode = 2 then
WScript.Echo "Succeed."
Else
WScript.Echo "Failure."
End If
Next
'WScript.StdOut.Write "Restart is required."
If installationResult.RebootRequired Then
'WScript.Echo "Required."
WScript.Echo "Computer restart is required to complete installation."
Else
WScript.Echo "Computer restart is not required."
End If
WScript.StdOut.Write vbCrLf & "Please press any key to continue."
InputKey = WScript.StdIn.ReadLine
If installationResult.RebootRequired Then
Dim objWshShell
Set objWshShell = WScript.CreateObject("WScript.Shell")
objWshShell.Run "%comspec% /c shutdown /r /t 0", 0, False
WScript.Quit(-1)
Else
WScript.Quit(0)
End If

I want to delete files from SFTP folder using VBScript

I have written some code but not working please suggest me how can I handle.
Function SFTPDelete(SFtpServerName, SFtpUser, SFtpPassword, LocalFolderPath, SFTPOutFolderPath)
On Error Resume Next
Dim mydate, mmddyyyy, sFTPScript, rc
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
rc = micPass
mydate = Date - 1
' mmddyyyy = Right("00" & Month(mydate),2) &"-"& Right("00" & Day(mydate),2) & "-" & CStr(Year(mydate))
sFTPScript = sFTPScript & "option batch on" & vbCrLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & SFtpUser & ":" & SFtpPassword & "#" & SFtpServerName & vbCrLf
sFTPScript = sFTPScript & "cd " & SFTPOutFolderPath & vbCrLf
sFTPScript = sFTPScript & "delete" & SFTPOutFolderPath & vbCRLf
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
'Write the input file for the sftp command to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files (x86)\WinSCP\winscp.exe"" /console /log=" & LocalFolderPath & "log_winscp_get_files.log /loglevel=1 -script=" & sFTPTempFile
oFTPScriptShell.Run sCmd
Wait 10
If Err.Number <> 0 Then
Reporter.ReportEvent micFail, "Error occured while delete file from FTP location ["& SFTPOutFolderPath&"] "
rc = micFail
Else
'oFTPScriptFSO.DeleteFile(LocalFolderPath&"log_winscp_get_files.log")
End If
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
SFTPDownload = rc
End Function
Please let me know what changes I have to do.
Your question is pretty vague.
But there are at least two obvious problems:
There's no delete command in WinSCP. There's rm command.
You are missing a space after the delete command (that should be rm command).
The path in the rm/delete command is redundant to the cd command and will actually delete the folder itself. If you want to delete only the file in the folder, use just * mask:
sFTPScript = sFTPScript & "rm *" & vbCRLf
You are missing the -hostkey switch in the open command to verify server hostkey.

wscript FTP download error

I am trying to use this vbs script by naterice.com. It seems working but downloaded files, or file are blank. Any idea? (Windows 2000, IIS6). Thanks.
DIM sSite
DIM sUsername
DIM sPassword
DIM sLocalPath
DIM sRemotePath
DIM sRemoteFile
sSite="xxx.xxx.xx"
sUsername="yyyy"
sPassword="password"
sLocalPath="C:\rss"
sRemotePath="/directory"
sRemoteFile="*.htm"
FTPDownload sSite, sUsername, sPassword, sLocalPath, sRemotePath, sRemoteFile
Function FTPDownload(sSite, sUsername, sPassword, sLocalPath, sRemotePath, sRemoteFile)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalPath = Trim(sLocalPath)
sOriginalWorkingDirectory = oFTPScriptShell.CurrentDirectory
oFTPScriptShell.CurrentDirectory = sLocalPath
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "USER " & sUsername & vbCRLF
sFTPScript = sFTPScript & sPassword & vbCRLF
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCRLF
sFTPScript = sFTPScript & "binary" & vbCRLF
' sFTPScript = sFTPScript & "ascii" & vbCRLF
sFTPScript = sFTPScript & "prompt n" & vbCRLF
sFTPScript = sFTPScript & "mget " & sRemoteFile & vbCRLF
sFTPScript = sFTPScript & "quit" & vbCRLF & "quit" & vbCRLF & "quit" & vbCRLF
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
sFTPResults = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
'Write the input file for the ftp command
'to a temporary file.
Set fFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
fFTPScript.WriteLine(sFTPScript)
fFTPScript.Close
Set fFTPScript = Nothing
oFTPScriptShell.Run "%comspec% /c FTP -n -s:" & sFTPTempFile & " " & sSite & " > " & sFTPResults, 0, TRUE
Wscript.Sleep 1000
'Check results of transfer.
Set fFTPResults = oFTPScriptFSO.OpenTextFile(sFTPResults, ForReading, FailIfNotExist, OpenAsDefault)
sResults = fFTPResults.ReadAll
fFTPResults.Close
'oFTPScriptFSO.DeleteFile(sFTPTempFile)
'oFTPScriptFSO.DeleteFile (sFTPResults)
If InStr(sResults, "226 Transfer complete.") > 0 Then
FTPDownload = True
ElseIf InStr(sResults, "File not found") > 0 Then
FTPDownload = "Error: File Not Found"
ElseIf InStr(sResults, "cannot log in.") > 0 Then
FTPDownload = "Error: Login Failed."
Else
FTPDownload = "Error: Unknown."
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function
Hello, I am trying to use this vbs script by naterice.com. It seems working but downloaded files, or file are blank. Any idea? (Windows 2000, IIS6). Thanks.
Here's an example that downloads a text file from MS's ftp server and saves it in the c:\user folder.
Run it in a command prompt with cscript to see error messages (both server and local), or change Outp.write to message boxes.
cscript "c:\path to script\ftp.vbs"
You must specify the url absolutely correctly. There isn't a helper to work out what you mean. Match case on the server path eg README.TXT on the server should also be upper case in your URL.
ADODB is a binary format. The code you had would only work reliably on English computers as windows translates characters for the language used. This code originally downloaded MS's Safety Scanner.
Set fso = CreateObject("Scripting.FileSystemObject")
Set Outp = Wscript.Stdout
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "ftp://ftp.microsoft.com/Softlib/README.TXT", False
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
Outp.writeline ""
Outp.writeline "Error getting file"
Outp.writeline "=================="
Outp.writeline ""
Outp.writeline "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Outp.writeline "Source " & err.source
Outp.writeline ""
Outp.writeline "HTTP Error " & File.Status & " " & File.StatusText
Outp.writeline File.getAllResponseHeaders
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\ReadMe.txt", 2
Thanks Fred for assistance, at the end I have found out that I have got some networks problems with my server. It accepts some traffic but not all... This may explain why the first script by naterice.com has been working at my computer and was not working at the server. The same may be true with your script.

SFTP Transfer with Proxy?

Can the following WinSCP VBScript file be modified to allow proxy connection?
'###########################################################################
'# Function: MISC_FTPUpload
'#
'# Description:
'# Uses the FSO object to FTP a file to a remote server
'#
'# Parameters:
'# (in) sSite - The site to FTP to
'# (in) sUsername - The username to log in with
'# (in) sPassword - The password to log in with
'# (in) sLocalFile - The Locally stored file to FTP to the remote server
'# (in) sRemotePath - The path to store the file in, on the remote server
'#
'# (out) - sError - The error output
'#
'# Return:
'# True - File successfully sent
'# False - File not successfully sent
'###########################################################################
Function MISC_FTPUpload(byVal sSite, byVal sUsername, byVal sPassword, byVal sLocalFile, byVal sRemotePath, byRef sError)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Dim oFTPScriptFSO
Dim oFTPScriptShell
Dim sOriginalWorkingDirectory
Dim sFTPScript
Dim sFTPTemp
Dim bRetCode
Dim sFTPTempFile
Dim oFTPScript
Dim sResults
Dim sOut
Dim sCmd
LOG_Write "MISC_FTPUpload called at: " & Now
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalFile = Trim(sLocalFile)
'----------Path Checks---------
'Here we will check the path, if it contains
'spaces then we need to add quotes to ensure
'it parses correctly.
If InStr(sRemotePath, " ") > 0 Then
If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
sRemotePath = """" & sRemotePath & """"
End If
End If
If InStr(sLocalFile, " ") > 0 Then
If Left(sLocalFile, 1) <> """" And Right(sLocalFile, 1) <> """" Then
sLocalFile = """" & sLocalFile & """"
End If
End If
'Check to ensure that a remote path was
'passed. If it's blank then pass a "\"
If Len(sRemotePath) = 0 Then
'Please note that no premptive checking of the
'remote path is done. If it does not exist for some
'reason, Unexpected results may occur.
sRemotePath = "\"
End If
'Check the local path and file to ensure
'that either the a file that exists was
'passed or a wildcard was passed.
If InStr(sLocalFile, "*") Then
If InStr(sLocalFile, " ") Then
sError = "Error: Wildcard uploads do not work if the path contains a space." & vbNewLine & "This is a limitation of the Microsoft FTP client."
LOG_Write sError
MISC_FTPUpload = False
Exit Function
End If
ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then
'nothing to upload
sError = "Error: File Not Found."
LOG_Write sError
MISC_FTPUpload = False
Exit Function
End If
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "option batch on" & vbCRLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "#" & sSite & vbCrLf
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCrLf
sFTPScript = sFTPScript & "put " & sLocalFile & vbCRLF
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
LOG_Write "Script for FTP File: " & vbNewLine & sFTPScript
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
LOG_Write "FTP Input file stored at: " & sFTPTempFile
'Write the input file for the ftp command
'to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files\WinSCP\WinSCP.com"" -script=" & sFTPTempFile
MISC_RunCmd sCmd, sOut, sError
LOG_Write sOut
Wscript.Sleep 1000
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
'Check results of transfer.
If sError = "" And InStr(sOut, "binary") >0 And InStr(sOut, "100%") >0 Then
MISC_FTPUpload = True
Else
sError = "Error: " & sError
LOG_Write sError
MISC_FTPUpload = False
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function
'###########################################################################
'# Function: MISC_FTPDownload
'#
'# Description:
'# Uses the FSO object to FTP a file from a remote server
'#
'# Parameters:
'# (in) sSite - The site to FTP from
'# (in) sUsername - The username to log in with
'# (in) sPassword - The password to log in with
'# (in) sLocalPath - The path to store the file in, on the local drive
'# (in) sLocalPath - The path to get the file from, on the remote drive
'# (in) sRemoteFile - The remotely stored file to FTP to the local drive
'#
'# (out) - sError - The error output
'#
'# Return:
'# True - File successfully retrieved
'# False - File not successfully retrieved
'###########################################################################
Function MISC_FTPDownload(byVal sSite, byVal sUsername, byVal sPassword, byVal sLocalPath, byVal sRemotePath, byVal sRemoteFile, byRef sError)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Dim oFTPScriptFSO
Dim oFTPScriptShell
Dim sOriginalWorkingDirectory
Dim sFTPScript
Dim sFTPTemp
Dim sFTPTempFile
Dim bRetCode
Dim oFTPScript
Dim sResults
Dim sCmd
Dim sOut
LOG_Write "MISC_FTPDownload called at: " & Now
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalPath = Trim(sLocalPath)
'----------Path Checks---------
'Here we will check the remote path, if it contains
'spaces then we need to add quotes to ensure
'it parses correctly.
If InStr(sRemotePath, " ") > 0 Then
If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
sRemotePath = """" & sRemotePath & """"
End If
End If
'Check to ensure that a remote path was
'passed. If it's blank then pass a "\"
If Len(sRemotePath) = 0 Then
'Please note that no premptive checking of the
'remote path is done. If it does not exist for some
'reason. Unexpected results may occur.
sRemotePath = "\"
End If
'If the local path was blank. Pass the current
'working direcory.
If Len(sLocalPath) = 0 Then
sLocalPath = oFTPScriptShell.CurrentDirectory
End If
If Not oFTPScriptFSO.FolderExists(sLocalPath) Then
'destination not found
sError = "Error: Local Folder Not Found."
LOG_Write sError
MISC_FTPDownload = False
Exit Function
End If
sOriginalWorkingDirectory = oFTPScriptShell.CurrentDirectory
oFTPScriptShell.CurrentDirectory = sLocalPath
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "option batch on" & vbCRLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "#" & sSite & vbCrLf
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCrLf
sFTPScript = sFTPScript & "get " & sRemoteFile & vbCRLF
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
LOG_Write "Script for FTP File: " & vbNewLine & sFTPScript
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
LOG_Write "FTP Input file stored at: " & sFTPTempFile
'Write the input file for the ftp command
'to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files\WinSCP\WinSCP.com"" -script=" & sFTPTempFile
MISC_RunCmd sCmd, sOut, sError
LOG_Write sOut
Wscript.Sleep 1000
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
'Check results of transfer.
If sError = "" And InStr(sOut, "binary") >0 And InStr(sOut, "100%") >0 Then
MISC_FTPDownload = True
Else
sError = "Error: " & sError
LOG_Write sError
MISC_FTPDownload = False
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function
The proxy would have to act as a Man in the Middle for this. SSH (the protocol SCP uses for data transfer) was designed to prevent this.
On the line, where you add the open command:
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "#" & sSite & vbCrLf
... add the -rawsettings switch followed by the options relevant for your kind of proxy:
For example:
sFTPScript = ... & " -rawsettings ProxyMethod=3 ProxyHost=proxy" & vbCrLf
For details refer to:
https://winscp.net/eng/docs/scriptcommand_open
https://winscp.net/eng/docs/rawsettings
To use the proxy, first use the WINSCP GUI to connect specifying the proxy details. This will add the details of proxy in the configuration file (which is in the same directory as winscp.com) and then it should work. You can then pass the path of this configuration file to your execute process task and call the WINSCP.com executable.

How to launch a Vb script that runs in 64 bit mode from a vbscript running under Wow64

I have a VB script that's being forced to run in Wow64 mode. I'd like to have it start either another script, or itself, in native 64 bit mode. Is there anyway to do that?
The initial script is being called by an explicit call to cscript.exe (not sure if this makes a difference or not)
Thanks
Apparently its pretty simple.
In Windows Vista and newer there is an alias folder at C:\Windows\Sysnative. If you call it it will not redirect to the c:\windows\SysWow64 32 bit folder but will force the native 64 bit executables to be called
http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx
Therefore, you can run a vbscript in 64 bit mode from a vbscript running in wow64 mode by calling %windir%\Sysnative\cscript.exe and then providing the name of your script as a parameter.
However, this only works in Windows Vista or newer. There is a hotfix which can enable this Sysnative folder in Windows XP/2003
http://support.microsoft.com/kb/942589
Place the following code at the top of your script to detect if the OS is 64bit then re-run in 32bit mode
' ***************
' *** 64bit check
' ***************
' check to see if we are on 64bit OS -> re-run this script with 32bit cscript
Function RestartWithCScript32(extraargs)
Dim strCMD, iCount
strCMD = r32wShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\SysWOW64\cscript.exe"
If NOT r32fso.FileExists(strCMD) Then strCMD = "cscript.exe" ' This probably won't work if we can't find the SysWOW64 Version
strCMD = strCMD & Chr(32) & Wscript.ScriptFullName & Chr(32)
If Wscript.Arguments.Count > 0 Then
For iCount = 0 To WScript.Arguments.Count - 1
if Instr(Wscript.Arguments(iCount), " ") = 0 Then ' add unspaced args
strCMD = strCMD & " " & Wscript.Arguments(iCount) & " "
Else
If Instr("/-\", Left(Wscript.Arguments(iCount), 1)) > 0 Then ' quote spaced args
If InStr(WScript.Arguments(iCount),"=") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") + 1) & """ "
ElseIf Instr(WScript.Arguments(iCount),":") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") + 1) & """ "
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
End If
Next
End If
r32wShell.Run strCMD & " " & extraargs, 0, False
End Function
Dim r32wShell, r32env1, r32env2, r32iCount
Dim r32fso
SET r32fso = CreateObject("Scripting.FileSystemObject")
Set r32wShell = WScript.CreateObject("WScript.Shell")
r32env1 = r32wShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If r32env1 <> "x86" Then
' we are not running in x86 mode, so run in that mode; check if we have done this already
For r32iCount = 0 To WScript.Arguments.Count - 1
r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
Next
' MsgBox "64bit (restarting) " & r32env2
If InStr(r32env2,"restart32") = 0 Then RestartWithCScript32 "restart32" Else MsgBox "Cannot find 32bit version of cscript.exe or unknown OS type " & r32env1
Set r32wShell = Nothing
WScript.Quit
Else
For r32iCount = 0 To WScript.Arguments.Count - 1
r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
Next
' MsgBox "32bit! " & r32env2
End If
'MsgBox "OS: " & r32env1 & VbCrLf & "Param: " & r32env2 & VbCrLf & "Script: " & WScript.FullName & VbCrLf & "Fullname: " & " " & Wscript.ScriptFullName
Set r32wShell = Nothing
Set r32fso = Nothing
' WScript.Quit
' *******************
' *** END 64bit check
' *******************

Resources