我正在使用以下脚本文件 (ftp_test_2.ps1) 将文件传输到 ftp 服务器:
#we specify the directory where all files that we want to upload are contained
$Dir="C:/Users/you-who/Documents/textfiles/"
#ftp server
$ftp = "ftp://192.168.100.101:21/"
$user = "aP_RDB"
$pass = "pw"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
#list every txt file
foreach($item in (dir $Dir "*.txt"))
{
"creating URI..."
$uri = New-Object System.Uri($ftp+$item.Name)
$uri
"attempting upload... $item"
$webclient.UploadFile($uri, $item.FullName)
}
Run Code Online (Sandbox Code Playgroud)
当 $ftp 设置为本地主机并连接到另一个 ftp 测试服务器时,这可以正常工作。但是,在生产 ftp 服务器上,服务器拒绝上传并显示 Powershell 错误:
Exception calling "UploadFile" with "2" argument(s): "The remote server …Run Code Online (Sandbox Code Playgroud)