---
updatedAt: 2025-08-14T13:54:08.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-sight/llms.txt
---

# Retrieving a specific log or collection of log files

```powershell PowerShell

param (
    [string]$id = $( Read-Host "Input Customer/Site name" )
)

$ftppath = "ftp://LOGIN:PASSWORDr@ftp.example.net/client_uploads"
$machine_name = $env:computername
$date = Get-Date -UFormat "%Y%m%d"

 

function makeFTPDirectory ($Username, $Password, $Path) {
    Write-Host ("FTP PATH", $Path)
    
    try {
        $makeDirectory = [System.Net.WebRequest]::Create($Path);      
        #$makeDirectory.Credentials = New-Object System.Net.NetworkCredential($Username,$Password);
        $makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory;
        $makeDirectory.GetResponse();
        Start-Sleep -s 5
    } Catch [Net.WebException]
    { try {
        #if there was an error returned, check if folder already existed on server
        $checkDirectory = [System.Net.WebRequest]::Create($Path);
        $checkDirectory.Credentials = New-Object System.Net.NetworkCredential($Username,$Password);
        $checkDirectory.Method = [System.Net.WebRequestMethods+FTP]::PrintWorkingDirectory;
        $response = $checkDirectory.GetResponse();
        #folder already exists!
        }
    catch [Net.WebException] {                
        #if the folder didn't exist, then it's probably a file perms issue, incorrect credentials, dodgy server name etc
    }    
}
    
}

function Upload_Files ($Files, $RemotePath) {
    $webclient = New-Object System.Net.WebClient 
    # enumerate the items array
    foreach ($file in $Files)
    {
          
          # if the item is NOT a directory, then process it.
          #if ($obj.Attributes -ne "Directory")
          if (Test-Path $file -PathType Leaf)
          {
                $obj = Get-ChildItem $file  
                Write-Host ("Uploading ", $obj)
                
                #"FTP Location $ftp/$item.name"
                #$uri = New-Object System.Uri($RemotePath+$obj.Name) 
                $foo = $RemotePath, $obj.Name
                $bar = [string]::join('/', $foo)
                $uri = New-Object System.Uri($bar) 
                Write-Host ("FTP Location", $bar)
                #$webclient.UploadFile($uri, $item.FullName) 
                $webclient.UploadFile($uri, $obj)             
          }
    }
}

makeFTPDirectory $ftpuname $ftppassword $ftppath/$id
makeFTPDirectory $ftpuname $ftppassword $ftppath/$id/$machine_name
makeFTPDirectory $ftpuname $ftppassword $ftppath/$id/$machine_name/$date


# initialize the items variable with the
# contents of a directory
#$Dir="C:\temp"  
#$items = Get-ChildItem -Path "$Dir"


$logfiles = "C:\Program Files (x86)\Advanced Monitoring Agent\debug.log", `
            "C:\Program Files (x86)\Advanced Monitoring Agent\debugfeature.log", `
            "C:\Program Files (x86)\Advanced Monitoring Agent\settings.ini", `
            "C:\ProgramData\ManagedAntivirus\ManagedAntivirus.log"

        

#Upload_Files $logfiles "$ftppath/$id/$machine_name/$date/"
$pathlist = $ftppath, $id, $machine_name, $date
$newftppath = [string]::join('/', $pathlist)
$newftppath

 
Upload_Files $logfiles $newftppath


```

```json Response Example
{"success":true}
```

# SCRIPT