【发布时间】:2015-10-28 05:16:15
【问题描述】:
我正在使用 jenkins 来实现 CI,并成功地将文件发布到构建服务器。 但是,部署到 App Server 并不起作用,因为 FTP 插件只是复制文件夹,而不是文件。 所以我正在编写一个powershell脚本来通过FTP复制文件。
到目前为止,我已经在谷歌搜索的帮助下写了这篇文章:
## Automate FTP uploads
## Go to destination
cd C:\TrashFolder
$location = Get-Location
"We are here: $location"
## Get files
$files = Get-ChildItem -recurse
## Get ftp object
$ftp_client = New-Object System.Net.WebClient
$ftp_address = "ftp://MyUserName:MyPassword@ftp://IPAddress"
## Make uploads
foreach($file in $files)
{
$directory = "";
$source = $file.DirectoryName + "\" + $file;
if ($File.DirectoryName.Length -gt 0)
{
$directory = $file.DirectoryName.Replace($Location,"")
}
$Directory += "/";
$FtpCommand = $ftp_address + $directory + $file
$uri = New-Object System.Uri($FtpCommand)
"Command is " + $uri + " file is $source"
$ftp_client.UploadFile($uri, $source)
}
但我得到了这个异常
Exception calling "UploadFile" with "2" argument(s): "The remote name could not be resolved: 'ftp'"
At C:\DeployScripts\FileUpload.ps1:26 char:5
+ $ftp_client.UploadFile($uri, $source)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
我们将不胜感激。 TIA
【问题讨论】:
-
地址解析出现错误。尝试 ping $ftp_address
标签: powershell jenkins ftp