I'm kinda new to PHP, and I'm trying to make a simple FTP upload script. It successfully connects to the server and logs in, but it can't upload. The transfer mode I use normally is ASCII (like I have it in the script), and for now, I have the mode set to passive (although I'll give a choice later on when I actually implement the script). (I starred out the password here, it is in the file, though.)
Here's the entire page (not much, just the script itself):
[PHP]<?php
$source_file='C :\cmd.txt';
$destination_fi le='cmd.txt';
$name='TestGuy' ;
$type='Text Document';
// set up basic connection
$conn_id = ftp_connect('ft p.pehjota.com') ;
// login with username and password
$login_result = ftp_login($conn _id,'pehjotaupl oads','******') ;
// check connection
if (!$conn_id){
echo "Connection failed!<br />";
exit;
} else {
echo "Connected. <br />";
}
if (!$login_result ){
echo "Login failed!<br />";
exit;
} else {
echo "Logged in.<br />";
}
// upload the file
$passive=ftp_pa sv($conn_id,tru e);
$upload=ftp_put ($conn_id,$dest ination_file,$s ource_file,FTP_ ASCII);
// check upload status
if (!passive){
echo 'Failed to enter passive mode.<br />';
}
else {
echo 'Entered passive mode.<br />';
}
if (!$upload) {
echo 'Upload failed! Could not upload "'.$source_file .'" to "http://www.pehjota.com/uploads/'.$destination_ file.'"<br />';
//mail('random@pe hjota.com','New Submission',$na me.' has tried to submit a '.$type.'. The file is located at: http://www.pehjota.com/uploads/'.$destination_ file,'From: name@email.com' );
} else {
echo 'Uploaded "'.$source_file .'" to <a href="http://www.pehjota.com/uploads/'.$destination_ file.'">"http://www.pehjota.com/uploads/'.$destination_ file.'"</a><br />';
mail('random@pe hjota.com','New Submission',$na me.' has submitted a '.$type.'. The file is located at: http://www.pehjota.com/uploads/'.$destination_ file);
}
// close the FTP stream
$close=ftp_clos e($conn_id);
if (close){
echo 'FTP connection successfully closed.';
}
?>[/PHP]
I also tried adjusting chmod permissions for the folder to which this would upload (to 777) just in case, but that did nothing.
Here's the entire page (not much, just the script itself):
[PHP]<?php
$source_file='C :\cmd.txt';
$destination_fi le='cmd.txt';
$name='TestGuy' ;
$type='Text Document';
// set up basic connection
$conn_id = ftp_connect('ft p.pehjota.com') ;
// login with username and password
$login_result = ftp_login($conn _id,'pehjotaupl oads','******') ;
// check connection
if (!$conn_id){
echo "Connection failed!<br />";
exit;
} else {
echo "Connected. <br />";
}
if (!$login_result ){
echo "Login failed!<br />";
exit;
} else {
echo "Logged in.<br />";
}
// upload the file
$passive=ftp_pa sv($conn_id,tru e);
$upload=ftp_put ($conn_id,$dest ination_file,$s ource_file,FTP_ ASCII);
// check upload status
if (!passive){
echo 'Failed to enter passive mode.<br />';
}
else {
echo 'Entered passive mode.<br />';
}
if (!$upload) {
echo 'Upload failed! Could not upload "'.$source_file .'" to "http://www.pehjota.com/uploads/'.$destination_ file.'"<br />';
//mail('random@pe hjota.com','New Submission',$na me.' has tried to submit a '.$type.'. The file is located at: http://www.pehjota.com/uploads/'.$destination_ file,'From: name@email.com' );
} else {
echo 'Uploaded "'.$source_file .'" to <a href="http://www.pehjota.com/uploads/'.$destination_ file.'">"http://www.pehjota.com/uploads/'.$destination_ file.'"</a><br />';
mail('random@pe hjota.com','New Submission',$na me.' has submitted a '.$type.'. The file is located at: http://www.pehjota.com/uploads/'.$destination_ file);
}
// close the FTP stream
$close=ftp_clos e($conn_id);
if (close){
echo 'FTP connection successfully closed.';
}
?>[/PHP]
I also tried adjusting chmod permissions for the folder to which this would upload (to 777) just in case, but that did nothing.
Comment