PowerShell Ftp upload PowerShell Ftp upload powershell powershell

PowerShell Ftp upload


I've used this script with success (from http://gallery.technet.microsoft.com/scriptcenter/80647f66-139c-40a4-bb7a-04a2d73d423c):

#we specify the directory where all files that we want to upload  $Dir="C:/Dir"    #ftp server $ftp = "ftp://ftp.server.com/dir/" $user = "user" $pass = "Pass"  $webclient = New-Object System.Net.WebClient $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  #list every sql server trace file foreach($item in (dir $Dir "*.trc")){     "Uploading $item..."     $uri = New-Object System.Uri($ftp+$item.Name)     $webclient.UploadFile($uri, $item.FullName)  } 


I am not familiar with using System.Net.WebClient, but is there a reason why you can't use ftp.exe?

function FTP-File($FTPserver, $FTPusername, $FTPpassword, $FTPfile){  #Build FTP script file and run FTP command  "open $FTPserver" | Out-File ftp.scr -Encoding ASCII  $FTPusername | Out-File ftp.scr -Encoding ASCII -Append  $FTPpassword | Out-File ftp.scr -Encoding ASCII -Append  "put " + $FTPfile | Out-File ftp.scr -Encoding ASCII -Append  "quit" | Out-File ftp.scr -Encoding ASCII -Append  ftp.exe -s:ftp.scr  Remove-Item ftp.scr}FTP-File "10.0.0.250" "username" "password" "c:\testfile.txt"


Try to set it on the webclient object (also check the properties of $proxy, depending on your environment you might to need to set some of them) :

$proxy = New-Object System.Net.WebProxy http://proxy:8080$webclient.Proxy = $proxy