Skip to content

Instantly share code, notes, and snippets.

@ethanpil
Created August 2, 2016 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanpil/2432a764619430f62d77f4a330105e95 to your computer and use it in GitHub Desktop.
Save ethanpil/2432a764619430f62d77f4a330105e95 to your computer and use it in GitHub Desktop.
Upload file via FTP in Curl
<?php
$ch = curl_init();
$localfile = '/path/to/file.zip';
$remotefile = 'filename.zip';
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp_login:password@ftp.domain.com/'.$remotefile);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment