PowerShell script to upload a file to a remote FTP server0 Reacties

I needed a simple script to upload a file remotely to an FTP server, and found a script on StackOverflow.

However, the script could use some improvements such as SSL. Here it is. Good luck with it

$ftp = [System.Net.WebRequest]::Create("ftp://ftp.yourserverblahblah.com/public/" + $args[0])
$ftp = [System.Net.FtpWebRequest]$ftp #cast
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile #"STOR"
$ftp.Credentials = new-object System.Net.NetworkCredential("someuser","incrediblepassword****")
$ftp.UseBinary = $true
$ftp.UsePassive = $true
$ftp.EnableSsl = $true

$fullPathIncFileName = $MyInvocation.MyCommand.Definition

$currentExecutingPath = [System.IO.Path]::GetDirectoryName($fullPathIncFileName)
$file = [System.IO.Path]::Combine($currentExecutingPath, $args[0])
Write-Host "Going To Copy " + $file
# read in the file as a stream.
$content = [System.IO.File]::OpenRead($file)

# get the request stream, and copy the bytes into it
$rs = $ftp.GetRequestStream()
$content.CopyTo($rs)
$rs.Close()
$content.Close()

Howto: Detect an AMD64 CPU within WOW64 mode?0 Reacties

WOW64 stands for Windows on Windows64. It emulates Win32 mode for programs that were compiled for Windows 32-bit mode. It _even_ will emulate SystemInfo API calls! So if you ask GetSystemInfo to supply info about the processor architecture, or if you query through API GetEnvironmentVariable(L"PROCESSOR_ARCHITECTURE"...) Wow64 will make your 32-bit feel comfortable by saying: "Yes, I am an Intel compatible x86 CPU!".

So I was puzzled, my SETUP needed to do some tasks and it had to simply detect wether or not we are on a x64 windows edition.
The solution seemed simple. Try it for yourselves.


Boot to Windows x64 (if not done so yet) and run file://C:\WINDOWS\SysWOW64\cmd.exe this is the good old 32-bit command prompt from the Windows XP time.

Let's examine the environment variables you might need. The output in my case would be...

ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\Administrator\Application Data
ClusterLog=C:\WINDOWS\Cluster\cluster.log
CommonProgramFiles=C:\Program Files (x86)\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=BGRULEZ
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Administrator
LOGONSERVER=\\BGRULEZ
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=AMD64 Family 15 Model 47 Stepping 0, AuthenticAMD
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=2f00
ProgramFiles=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
USERDOMAIN=BGRULEZ
USERNAME=Administrator
USERPROFILE=C:\Documents and Settings\Administrator
VS80COMNTOOLS=C:\Develop\VS2005\Common7\Tools\
windir=C:\WINDOWS

Evidentially you must solve the 'detect my AMD64' challenge through reading a new variable, named 'PROCESSOR_ARCHITEW6432' and not PROCESSOR_ARCHITECTURE.
If the variable does not exist, you are obviously running in a native win32 environment.

Update july 26 2006: Somebody made me awake, and pointed to the Kernel32 function: IsWow64Process(..) (see msdn).