Question: Linux PHP Site Converting from FTP to SFTP
I took over a php website running on Linux. We need to convert from using ftp to sftp. The code prompts the user for the local file and then uses php error ftp to put the file on the local server. Currently we are using the following:
$ftp_user = FTP_USER; $ftp_pass = FTP_PASS; $ftp_server = FTP_SERVER; $ftp_destination_path = FTP_DESTINATION_PATH; $url_path = "uploads/"; if (!($conn_id = @ftp_connect($ftp_server))) return('error connecting'); if (!($login_result = @ftp_login($conn_id, $ftp_user, $ftp_pass))) return('error logging in'); $filename_fixed = str_replace(" ", "_", $file['name']); $filename_fixed = str_replace("/", "-", $filename_fixed); $destination_file = $ftp_destination_path . $filename_fixed; if (!($upload = @ftp_put($conn_id, $destination_file, $file['tmp_name'], FTP_BINARY))) die("Cannot upload to location $destination_file"); ftp_close($conn_id);
Is there anything native in php for sftp? Seems I have to install third party php error package like PECL ssh2? I need help as I can't find a good example for how to convert what I have to sftp?