Creating a directory on remote FTP using powershell

前端 未结 1 1158
南旧
南旧 2021-01-18 10:19

I\"m able to put a file up to a remote FTP with a modified version of...

          $File = \"D:\\Dev\\somefilename.zip\"
          $ftp = \"ftp://username:pa         


        
相关标签:
1条回答
  • 2021-01-18 10:43

    I use function Create-FtpDirectory

    function Create-FtpDirectory {
      param(
        [Parameter(Mandatory=$true)]
        [string]
        $sourceuri,
        [Parameter(Mandatory=$true)]
        [string]
        $username,
        [Parameter(Mandatory=$true)]
        [string]
        $password
      )
      if ($sourceUri -match '\\$|\\\w+$') { throw 'sourceuri should end with a file name' }
      $ftprequest = [System.Net.FtpWebRequest]::Create($sourceuri);
      $ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::MakeDirectory
      $ftprequest.UseBinary = $true
    
      $ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password)
    
      $response = $ftprequest.GetResponse();
    
      Write-Host Upload File Complete, status $response.StatusDescription
    
      $response.Close();
    }
    

    Taken from Ftp.psm1 where you can find also other functions for FTP.

    To others: sorry for not following well known verb-noun pattern. ;)

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