Transfert de fichier par SFTP avec cURL/PHP
Bonjour à tous,
Je tente d'uploader un fichier sur un serveur sécurisé avec des clés privées/publiques.
L'upload ne fonctionne pas et je n'arrive pas à comprendre le fichier log qui est généré.
Voici mon script:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| <?php
// (0) FTP SETTINGS
define("SFTP_HOST", "sftp.machin.be/INTEST/");
define("SFTP_USER", "cestmoi");
define("SFTP_KEY_PASSWORD", "motdepasse");
define("SFTP_PRIVATE_KEY", "private_key.ppk");
define("SFTP_PUBLIC_KEY", "public_key.txt");
$verbose = fopen("log.txt", "w+");
$source = "FI.DIMN.123456.20170213.00001.R.1.1"; // File to upload to FTP server
//$source = "FILE.txt"; // File to upload to FTP server
$destination = "FI.DIMN.123456.20170213.00001.R.1.1"; // File name on FTP server
// (1) INIT CURL + LOCAL FILE
$curl = curl_init();
$file = fopen($source, 'r');
// (2) SET CURL OPTIONS
curl_setopt_array($curl, [
CURLOPT_VERBOSE => TRUE,
CURLOPT_CERTINFO => TRUE,
CURLOPT_FAILONERROR => TRUE,
CURLOPT_STDERR => $verbose,
CURLOPT_URL => SFTP_HOST . $destination,
CURLOPT_PORT => 8022,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_SSH_AUTH_TYPES => CURLSSH_AUTH_HOST,
CURLOPT_SSH_PUBLIC_KEYFILE => SFTP_PUBLIC_KEY,
CURLOPT_SSH_PRIVATE_KEYFILE => SFTP_PRIVATE_KEY,
CURLOPT_USERNAME => SFTP_USER,
CURLOPT_KEYPASSWD => SFTP_KEY_PASSWORD,
CURLOPT_UPLOAD => TRUE,
CURLOPT_INFILE => $file,
CURLOPT_INFILESIZE => filesize($source)
]);
// (3) EXECUTE CURL
curl_exec($curl);
// (4) CLOSE CONNECTION + FILE
curl_close($curl);
fclose($file);
?> |
Et le log qui est créé:
* Trying 12.34.567.89...
* TCP_NODELAY set
* Connected to sftp.machin.be (12.34.567.89) port 8022 (#0)
* Server auth using Basic with user 'cestmoi'
> PUT /INTEST/FI.DIMN.123456.20170213.00001.R.1.1 HTTP/1.1
Host: sftp.machin.be:8022
Authorization: Basic xxxxyyyzzz
Accept: */*
Content-Length: 949
Expect: 100-continue
* Done waiting for 100-continue
* We are completely uploaded and fine
* Closing connection 0
Je suis en erreur là ou pas dans le log ?
Merci à vous pour l'aide.