I'm new with PowerShell and I'm working on a Script that has to download files from different routes on a Linux machine by FTP in other routes of a Windows machine and also move them to another destination within Linux, basically like this:
So far for what I have researched I have to make the connection by "webclient" and the code that I have is the following:
#Linux source folders
$source1="/source1/"
$source2="/source2/"
$source3="/source3/"
#ftp server
$ftp = "ftp://192.168.0.2/../../"
$user = "usu1"
$pass = "usu1"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
#Download from source1 folder
foreach($item in (Get-ChildItem $source1 "*")){
"Uploading $item..."
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.DownloadFile($uri, $item.FullName)
}
#Download from source2 folder
foreach($item in (Get-ChildItem $source2 "*")){
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.DownloadFile($uri, $item.FullName)
}
#Download from source3 folder
foreach($item in (Get-ChildItem $source3 "*")){
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.DownloadFile($uri, $item.FullName)
}
And I get the following error:
Get-ChildItem : No se encuentra la ruta de acceso 'C:\source1\' porque no existe.
En línea: 16 Carácter: 23
As far as I can see, it tries to search in Windows.
Thank you in advance for the help you can give me.
Greetings.