Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (13.1k points)
edited by
I am trying to deploy my application using Azure DevOps. Is it possible to download all the images during the build of pipeline? Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

You can try this powershell scripts to coonect to FTP server and then you can download the files:

#FTP Server Information - SET VARIABLES

$ftp = "ftp://XXX.com/" 

$user = 'UserName' 

$pass = 'Password'

$folder = 'FTP_Folder'

$target = "C:\Folder\Folder1\"

#SET CREDENTIALS

$credentials = new-object System.Net.NetworkCredential($user, $pass)

function Get-FtpDir ($url,$credentials) {

    $request = [Net.WebRequest]::Create($url)

    $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory

    if ($credentials) { $request.Credentials = $credentials }

    $response = $request.GetResponse()

    $reader = New-Object IO.StreamReader $response.GetResponseStream() 

    while(-not $reader.EndOfStream) {

        $reader.ReadLine()

    }

    #$reader.ReadToEnd()

    $reader.Close()

    $response.Close()

}

#SET FOLDER PATH

$folderPath= $ftp + "/" + $folder + "/"

$files = Get-FTPDir -url $folderPath -credentials $credentials

$files 

$webclient = New-Object System.Net.WebClient 

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 

$counter = 0

foreach ($file in ($files | where {$_ -like "*.txt"})){

    $source=$folderPath + $file  

    $destination = $target + $file 

    $webclient.DownloadFile($source, $target+$file)

    #PRINT FILE NAME AND COUNTER

    $counter++

    $counter

    $source

}

After that, you can publish those files to the Artifacts by PublishBuildArtifacts.

Hope this helps.

Want to become an Azure DevOps Expert? join azure devops certification now!!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...