Author Posts

May 22, 2017 at 1:47 pm

Hi There,

i want to use the following script to sent some txt files by powershellscript to FTP server once a week:

$Dir="D:\temp"

#ftp server
$ftp = "ftp://172.16.2.16/"
$user = "username"
$pass = "Password"

$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 "*.txt")){
"Uploading $item..."
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.UploadFile($uri, $item.FullName)
}

Only we connecting to the homefolder of the ftp user. Is there a way to i can browse to antoher folder before uploading the .txt files?

Thanks in advanced.

May 23, 2017 at 8:10 pm

Look at using this module. I've used it at several customers and it did the job: https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb