Sapien technologies just released a com DLL to support simple FTP transfers. It supports the get/put FTP verbs, and I already tested them successfully. Its free to use and can be downloaded from Sapien's website. Thanks Sapien!
The download file includes two VBScripts files, one for upload and one for downloads. Here's a simple conversion to PowerShell.
Before starting using the functions, read the readme file, copy the DLL to system32 directory and register it:
regsvr32.exe ftp.dll
Cool, lets start
###############3
function Get-FTPFile{
param(
[string]$url,
[string]$port=21,
[string]$user,
[string]$pass,
[string]$RemoteFilePath,
[string]$localPath
)
$ftp = new-object -com Primalscript.FTPTransfer;
$ftp.Passive = 1;
$ftp.port = $port;
if($ftp.Connect($url,$user,$pass) -eq 0){
"Can't connect. " + $ftp.Status;
} else {
"Starting download"
If($ftp.Get($RemoteFilePath,$localPath) -eq 0){
"Error downloading file " + $ftp.Status;
} Else {
"Download complete";
}
$ftp.Disconnect();
}
}
Usage:
Get-FTPFile <ftpUrl> <port> <username> <password> <RemoteFilePath> <localDonloadPath>
############################
function Put-FTPFile{
param(
[string]$url,
[string]$port=21,
[string]$user,
[string]$pass,
[string]$localFile,
[string]$RemotePath
)
$ftp = new-object -com Primalscript.FTPTransfer;
$ftp.Passive = 1;
$ftp.port = $port;
if($ftp.Connect($url,$user,$pass) -eq 0){
"Can't connect. " + $ftp.Status;
} else {
if($ftp.Put($RemotePath,$localFile) -eq 1){
"success upload";
} else {
"Error uploading file. " +$ftp.Status;
}
$ftp.Disconnect();
}
}
Usage:
Get-FTPFile <ftpUrl> <port> <username> <password> <localUploadFile> <RemoteUploadPath>
##############
I'm maybe missing something, but I noticed when using the Put-FTPFile that even if the upload was successful, Put() returns 1 (error???) instead of 0. I commented about it in Spain's website FTP tool page.
UPDATE 09/19/2007:
Here's Don Jones reply:
0 is bad, 1 is good news.
1 = success (C++ TRUE)
0 = failure (C++ FALSE)
After all, I did miss something :-)
Thanks Don.