How can I add FTP website deployment to a VS2015/TFS2013 build process

后端 未结 1 1219
逝去的感伤
逝去的感伤 2021-01-28 00:26

I have a successful build operating. Now I would like to have the build definition publish the site to my staging location. I tried to use a publishing profile that functions

相关标签:
1条回答
  • 2021-01-28 00:54

    Just as mentioned in the error message FTP is not supported on msbuild command line.

    You should switch to a PowerShell solution, you can reference below PS sample to upload the build via FTP. See more details here.

    $ftpWebRequest = [System.Net.FtpWebRequest]::Create((New-Object System.Uri("ftp://your_ftp_server")))
    $ftpWebRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
    
    $inputStream = [System.IO.File]::OpenRead($filePath)
    $outputStream = $ftpWebRequest.GetRequestStream()
    
    [byte[]]$buffer = New-Object byte[] 131072;
    $totalReadBytesCount = 0;
    $readBytesCount;
    
    while (($readBytesCount = $inputStream.Read($buffer, 0, $buffer.Length)) -gt 0)
    {
    $outputStream.Write($buffer, 0, $readBytesCount)
    $totalReadBytesCount += $readBytesCount
    $progress = [int]($totalReadBytesCount * 100.0 / $inputStream.Length)
    Write-Progress -Activity "Uploading file..." -PercentComplete $progress -CurrentOperation "$progress% complete" -Status "Please wait."
    }
    $outputStream.Close();
    $outputStream = $null;
    Write-Progress -Activity "Uploading file..." -Completed -Status "Done!"
    

    You can also reference this article: Deploying Web Sites using TFS Deployer, PowerShell and FTP

    Update:

    That's just a sample, the $filePath should be your publish path, that means you can use msbuild to publish the website to local or UNC path, then call powershell to copy/upload all the files (including entire folder structure) from that path to FTP server. If above script not worked, you can also reference another script here to upload the entire directory : https://www.kittell.net/code/powershell-ftp-upload-directory-sub-directories/

    0 讨论(0)
提交回复
热议问题