Untitled
unknown
plain_text
2 years ago
1.2 kB
18
Indexable
<?php
$localFile = '/path/to/local/file.txt';
$remoteFile = '/path/to/remote/file.txt';
$sftpServer = 'sftp://your-sftp-server.com'; // Replace with your SFTP server details
$username = 'your-username'; // Replace with your SFTP username
$password = 'your-password'; // Replace with your SFTP password
$ch = curl_init();
// Set the URL to connect to
curl_setopt($ch, CURLOPT_URL, $sftpServer . $remoteFile);
// Enable verbose output for debugging (optional)
//curl_setopt($ch, CURLOPT_VERBOSE, true);
// Set the username and password for authentication
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
// Set the transfer mode to binary
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
// Set the method to upload
curl_setopt($ch, CURLOPT_UPLOAD, true);
// Set the local file path
curl_setopt($ch, CURLOPT_INFILE, fopen($localFile, 'r'));
// Set the file size
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile));
// Execute the request
$result = curl_exec($ch);
// Check for errors
if($result === false) {
echo 'Error: ' . curl_error($ch);
} else {
echo 'File uploaded successfully.';
}
// Close the cURL resource
curl_close($ch);
?>
Editor is loading...