php - How can I open a file from another ftp and write? -
i tried open file in ftp , write coulnd how can that?
$ftpstream = @ftp_connect('****'); //login ftp server $login = @ftp_login($ftpstream, '****', '***'); if($login) { echo "conectado"; $fp = fopen('file.txt', 'w'); fwrite($fp, '1'); fwrite($fp, '23'); fclose($fp); }
the code have posted wrong. opens ftp stream (ftp_connect
), writes file local file system (fopen
). ftp stream won't allow write fwrite
- need use commands transfer entire files.
you can want fopen
if use ftp://
scheme.
for example:
$fp = fopen("ftp://user:password@example.com/file.txt","w"); fwrite($fp, '1'); fwrite($fp, '23'); fclose($fp);
alternativley, can write file local file system , use ftp stream transfer it:
$file = 'somefile.txt'; // create file in local file system here. $remote_file = 'readme.txt'; // set basic connection $conn_id = ftp_connect($ftp_server); // login username , password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // upload file if (ftp_put($conn_id, $remote_file, $file, ftp_ascii)) { echo "successfully uploaded $file\n"; } else { echo "there problem while uploading $file\n"; } // close connection ftp_close($conn_id);
as always, clear on want do.
php ftp reference here
php scheme & wrapper reference (for use fopen
) here
Comments
Post a Comment