PowerShell备份文件夹,所有文件上传ftp

时间:2017-08-15 22:43:44

标签: windows powershell ftp backup

我正在尝试将文件夹从本地计算机上传到包含所有内容(所有类型的文件,子文件夹)的FTP文件夹。我尝试发布脚本不会收到错误,但是当我尝试检查FTP没有上传文件或文件夹时。

$source = "E:\test"
$destination = "ftp://user:password@x.x.x.x/disk1/ftp/SRV/Tes"

$webclient = New-Object -TypeName System.Net.WebClient

$files = Get-ChildItem $source
$Today = Get-Date -format "yyyy-MM-dd"

foreach ($file in $file)
{
    Write-Host "Uploading $file"
    $webclient.UploadFile("$destination/$file", $file.FullName)
} 

$webclient.Dispose()

foreach ($file in $file)更改为foreach ($file in $files)后,我收到以下错误:

Uploading afas
Exception calling "UploadFile" with "2" argument(s): "An exception occurred
during a WebClient request."
At C:\Users\Administrator\Desktop\scriptas kopijavimui.ps1:12 char:5
+ $webclient.UploadFile("$destianation/$file", $file.FullName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
     + FullyQualifiedErrorId : WebException Uploading Image.bmp

0 个答案:

没有答案