upload file to ftp server using power shell

#folder path
$Dir= 'C:\Uploadftp\ftpfiles\'
#ftp server settings
$ftp = 'ftp://ftpserver/'
$user = 'administrator'
$pass = '*********'
$webclient = New-Object System.Net.WebClient 
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)  

    #Searching for files
    foreach($item in (dir $Dir "*.*"))
    {
        #Set default network status to 1
        $onNetwork = "1"
            try{
                $uri = New-Object System.Uri($ftp+$item.Name)
                $webclient.UploadFile($uri, $item.FullName)
            } catch [Exception] {
                $onNetwork = "0"
                write-host $_.Exception.Message;
            }
            
}   

Change the bold value based on you requirement.

Popular posts from this blog

Shrink you container size up to 95%.

alma linux: dnf Module yaml error: Unexpected key in data