title: multipart/form-data Cerberus FTP
body: <p>For the past week i´ve been trying to figure how to upload files to Cerberus FTP via HTTP request, but i keep getting the same response from the server.</p>
  
  <p>If i change the contentype to something else it fails with a CSRF-check error.</p>
  
  <p>Any ideas ?</p>
  
  <p>It seems to be a formatting issue, but i cant figure where. In WinDiff the request is slighly off because there is an extra space after the Cookie attribute. Does this request type have to be 100% accurate in terms of spaces and such ? </p>
  
  <p>In Fiddler the requests look identical.</p>
  
  <p>Let me know if the website load script is required, the form didnt let me upload the entire script.   </p>
  
  <pre><code>      "
  Response: 
      HTTP/1.1 200 Ok
      Server: CerberusFTPServer/9.0
      X-Frame-Options: SAMEORIGIN
      X-Content-Type-Options: nosniff
      X-XSS-Protection: 1
      Content-Security-Policy: frame-ancestors 'self'
      Referrer-Policy: same-origin
      Cache-Control: no-cache, private, must-revalidate
      Content-Type: application/json; charset=utf-8
      Set-Cookie: cftpSID=w6QPdMOWDsO_wq-Dsw-Cj8KSw57CjwjDlQnDvistBw; Path=/; HttpOnly;
      Date: Tue, 15 Jan 2019 09:22:24 GMT
      Content-Length: 126
  
      {"files":[{"delete_type":"","delete_url":"","error":"Form data not complete","name":"","size":0,"thumbnail_url":"","url":""}]}"
  
  
  
  
  
  #upload
  
  $file = "C:\Users\michael\Desktop\1024000.txt"
  
      $fileName = Split-Path $File 
      $boundary = [guid]::NewGuid().ToString()
  
      $fileBinary = [System.IO.File]::ReadAllBytes($File)
  
      $enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
  
      $fileEncoded = $enc.GetString($fileBinary)
  
  
  $Uri='http://172.16.0.82/file/upload'
  
  $ContentType = "text/plain"
  
  $boundary = "-----------------------------7e3a63120b435"        
  
  $FNAME = "1024000.txt"
  
  $FileContent= $fileEncoded
  
  $template = @' 
  {5}
  {0}
  Content-Disposition: form-data; name="cd"
  
  /
  {0}
  Content-Disposition: form-data; name="csrftoken"
  
  {4}
  {0}
  Content-Disposition: form-data; name="files[]"; filename="{1}"
  Content-Type: {2}
  
  {3}
  {0}--
  
  '@
  
  $conn = "Connection: Keep-Alive"
  $body = $template -f $boundary, $FNAME, $ContentType, $FileContent, $csrftoken, $conn
  
  
  $ConType="multipart/form-data; boundary="+$boundary
  
  $header=@{
  'X-Requested-With'='XMLHttpRequest'
  'Accept-Encoding'= 'gzip, deflate'
  'Referer'='http://172.16.0.82/file'
  'Content-Type'= "$ConType"
  'Accept'='application/json, text/javascript, */*; q=0.01'
  'Pragma'='no-cache'
  'User-Agent' = 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'
  'Host' = '172.16.0.82'
  'Accept-Language' = 'en-DK,en-GB;q=0.8,en-US;q=0.6,en;q=0.4,da;q=0.2'
  }
  
  
  Invoke-webrequest -Uri $Uri -Method POST -Body $body -Headers $header -websession $session
  </code></pre>