How to set file permission 0555 using ftp_chmod?
<?php
$ftp_server = "example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "user", "password");
$file = "path/index.php";
ftp_chmod($ftp_conn, 0555, $file)
?>
using this script i can not change file permission to 0555!! using this script i can change 0666,0777 but i cant not change to 0555
output of above script is 0655!!
Related
I upload XML file through FTP:
$ftp = "ftp";
$username = "username";
$pwd = "password";
$filename = $_FILES[$xyz][$abc];
$tmp = $_FILES['file']['tmp_name'];
$destination = "/Content/EnquiryXML ";
$connect = ftp_connect($ftp)or die("Unable to connect to host");
ftp_login($connect,$username,$pwd)or die("Authorization Failed");
echo "Connected!<br/>";
if(!$filename)
{
echo"Please select a file";
}
else
{
ftp_put($connect,$destination.'/'.$filename,$tmp,FTP_ASCII)or die("Unable to upload");
echo"File successfully uploaded to FTP";
}
I want to send the XML file created using DOMDocument to a FTP server but I am not able.
The ftp_put returns false.
Most typical cause of problems with ftp_put (or any other transfer command like ftp_get, ftp_nlist, ftp_rawlist, ftp_mlsd) is that PHP defaults to the active mode. And in 99% cases, one has to switch to the passive mode, to make the transfer working. Use the ftp_pasv function.
$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization failed");
// turn passive mode on
ftp_pasv($connect, true) or die("Unable switch to passive mode");
The ftp_pasv must be called after ftp_login. Calling it before has no effect.
See also:
PHP ftp_put fails with "Warning: ftp_put (): PORT command successful"
my article on the active and passive FTP connection modes.
Further, if your FTP server is reporting an incorrect IP address in the response to the PASV command (what is quite common, if the server is behind firewall/NAT), you might need to workaround it by using:
ftp_set_option($connect, FTP_USEPASVADDRESS, false);
See PHP FTP + Passive FTP Server Behind NAT.
Though the right solution in this case, is to get the server fixed.
This worked:
// connect and login to FTP server
$ftp_server = "host";
$ftp_username = "username";
$ftp_userpass = "password";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file ="$abc";
// upload file
if (ftp_put($ftp_conn, "/$abc" , $file, FTP_ASCII)){
echo "Successfully uploaded $file.";
} else {
echo "Error uploading $file";
}
// close connection
ftp_close($ftp_conn);
I can't loggon to linux server when I'm trying to get some files from home directory..
<?php
// connect and login to FTP server
$ftp_server = "xxxx";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, 'xxx', 'xxx');
var_dump($login);
// then do something...
// close connection
ftp_close($ftp_conn);
?>
what i supposed to do !?? I'm getting this error :
Warning: ftp_login(): Permission denied
I upload XML file through FTP:
$ftp = "ftp";
$username = "username";
$pwd = "password";
$filename = $_FILES[$xyz][$abc];
$tmp = $_FILES['file']['tmp_name'];
$destination = "/Content/EnquiryXML ";
$connect = ftp_connect($ftp)or die("Unable to connect to host");
ftp_login($connect,$username,$pwd)or die("Authorization Failed");
echo "Connected!<br/>";
if(!$filename)
{
echo"Please select a file";
}
else
{
ftp_put($connect,$destination.'/'.$filename,$tmp,FTP_ASCII)or die("Unable to upload");
echo"File successfully uploaded to FTP";
}
I want to send the XML file created using DOMDocument to a FTP server but I am not able.
The ftp_put returns false.
Most typical cause of problems with ftp_put (or any other transfer command like ftp_get, ftp_nlist, ftp_rawlist, ftp_mlsd) is that PHP defaults to the active mode. And in 99% cases, one has to switch to the passive mode, to make the transfer working. Use the ftp_pasv function.
$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization failed");
// turn passive mode on
ftp_pasv($connect, true) or die("Unable switch to passive mode");
The ftp_pasv must be called after ftp_login. Calling it before has no effect.
See also:
PHP ftp_put fails with "Warning: ftp_put (): PORT command successful"
my article on the active and passive FTP connection modes.
Further, if your FTP server is reporting an incorrect IP address in the response to the PASV command (what is quite common, if the server is behind firewall/NAT), you might need to workaround it by using:
ftp_set_option($connect, FTP_USEPASVADDRESS, false);
See PHP FTP + Passive FTP Server Behind NAT.
Though the right solution in this case, is to get the server fixed.
This worked:
// connect and login to FTP server
$ftp_server = "host";
$ftp_username = "username";
$ftp_userpass = "password";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file ="$abc";
// upload file
if (ftp_put($ftp_conn, "/$abc" , $file, FTP_ASCII)){
echo "Successfully uploaded $file.";
} else {
echo "Error uploading $file";
}
// close connection
ftp_close($ftp_conn);
I'm writing a php script that gets called via ajax in javascript. I'm tyring to connect to an ftp server and list all the files in the "public_html" folder.
I also wanted to print the current ftp dir but when when I try, it prints as empty in the console.
I can connect to the ftp server, but I can't tell what dir is the current one.
//Get ftp user/pass
$ftp_server = "ftp." . $_POST['hostname'];
$ftp_username = $_POST['user'];
$ftp_userpass = $_POST['pass'];
echo "console.log('attempting to connect to ftp host: $ftp_server, user: $ftp_username, password: $ftp_userpass');\n";
$ftp_conn = ftp_connect($ftp_server) or die("alert('Could not connect to $ftp_server');\n");
// turn passive mode on
//ftp_pasv($ftp_conn, true);
ftp_chdir($ftp_conn, 'public_html');
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
// then do something...
echo "console.log('Connected to FTP');\n";
// get contents of the current directory
$curdir = ftp_pwd($ftp_conn);
echo "console.log('Current dir: $curdir');\n";
$contents = ftp_nlist($ftp_conn, ".");
// output $contents
echo "var files = [];";
foreach ($contents as $file){
echo "var tempFile = '$file';\n
files.push(tempFile);\n";
}
echo "console.log(files);\n";
// close connection
ftp_close($ftp_conn);
?>
swap these two lines from:
ftp_chdir($ftp_conn, 'public_html');
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
to:
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
ftp_chdir($ftp_conn, 'public_html');
I have some problems, when using ftp_pasv();
Try to comment this line:
ftp_pasv($ftp_conn, true);
<?php
ini_set('max_execution_time', '0');
$host = '234.546.155.485';
$usr = 'fgfgfgdf';
$pwd = 'fghghh';
// file to move:
$file = 'http://vsomesite.com/file.flv';
$ftp_path = '/public_html/video57242/test.flv';
// connect to FTP server (port 21)
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
// send access parameters
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
// turn on passive mode transfers (some servers need this)
// ftp_pasv ($conn_id, true);
// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $file, FTP_ASCII);
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
?>
upload fails when the file is remote not local. what problem?
Your variables don't add up. You use $local_file in your ftp_put() call, but you only declare $file earlier in the script
And are you sure you should be using FTP_ASCII for a FLV file? I'd have thought that was binary.
Edit
Scratch my first point. Seems you edited it away :)