how can i do extract zip file for script setup in safe_mode on
i'm trying this
require_once('pclzip.lib.php');
$archive = new PclZip('archive.zip');
if (($v_result_list = $archive->extract()) == 0) {
die("Error : ".$archive->errorInfo(true));
}
echo "<pre>";
var_dump($v_result_list);
echo "</pre>";
but i get OWNER error on the extracted dir
How do i fix this problem, or i think re connect to this ftp again and upload and extract file to this ftp
$local_file = './arcive.zip';
$ftp_path = '/extract';
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
How do you think i can do?
when a file is unzipped it preserves the owner and permissions information. In your case it's likely that the permissions do not allow world access. if the owner of the file is different from the account that PHP runs under, you cannot chown the file or change permissions. Unless PHP is run as root (and who does that?). in safe mode you can't even do that as root.
Ask the person who archives the file to make it "read & write" for everybody.
As for the second part of the question, you cannot extract something on another server over ftp protocol. you'd have to ssh into the server.
http://phpseclib.sourceforge.net might be of help in that
Related
I am trying to come up with a scehduled copy code with php.
I dont have problem copying from shared folder via eg //xxx.xx.xxx/folder/filename.csv ( remote computer ). I have some files located at a ftp server. How can I do the same?
Appreciate any help
$file = 'ftp://xx.xx.xxx.xx/Log/123.csv';
$newfile = 'spc/ems_files/123.csv';
if ( copy($file, $newfile) ) {
echo "Copy success!";
} else {
echo "Copy failed.";
}
Additional info
Bask on the feed I used php ftp function to connect to the ftp using below code
based it said failed to connect. I can connect it with a FTP software like filezilla without much issue. What is wrong ?
$ftp_server = "10.76.170.123";
$ftp = ftp_connect("10.76.170.123");
if (!$ftp) die('could not connect.');
// login
$r = ftp_login($ftp, "anonymous", "");
if (!$r) die('could not login.');
// enter passive mode
$r = ftp_pasv($ftp, true);
if (!$r) die('could not enable passive mode.');
// get listing
$r = ftp_rawlist($ftp, "Log");
var_dump($r);
It looks like what you're doing should be possible, as long as the FTP server supports passive mode and you are using the correct credentials. I would double-check the path to the file, on the FTP server, is correct too.
http://php.net/manual/en/wrappers.php
http://php.net/manual/en/wrappers.ftp.php
Here are some other solutions you could try ...
SFTP using phpseclib - http://phpseclib.sourceforge.net/sftp/examples.html
FTP Functions in PHP - http://php.net/manual/en/book.ftp.php
I solved the problem.default ftp connection used email address as password
I used this to connect to the ftp successfully
$r = ftp_login($ftp, "anonymous", "anonymous#domain.com");
So I chose to use php FTP function to do the downloading task
I need to move a backup of my database file to another server automatically using cron. I have some code and it's connecting to the ftp server fine, the problem is it will not move the file. I don't know how to make it show the exact error other than "FTP upload failed!" so I don't know what the real problem is, however, I believe it's got to do with the "real" path of the file on the server and/or the real path of the directory of the other server where it's placing the file.
Any help would be great.
$server = "MyServer";
$ftp_user_name = "MyUsername";
$ftp_user_pass = "MyPassword";
$source = "bumail_data/db-backup-05-09-15__17:23.sql";
$dest = 'db-backup-05-09-15__17:23.sql';
$connection = ftp_connect($server);
$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
ftp_pasv ( $connection, true );
if (!$connection || !$login) { die('Connection attempt failed!'); }
$upload = ftp_put($connection, $dest, $source, FTP_BINARY);
if (!$upload) { echo 'FTP upload failed!'; }
ftp_close($connection);
The file $source is located in httpdocs/bumail_data/FILE.sql
The folder on the other server I want to put the file in is located before the public_html on a dir named dbbackup. So I guess that is the root dir but not sure.
I hope that helps you understand where the files are and what I maybe need to put in the script. I have tried everything I can think of from ../dir/file to var/host/root/dir/file and so on. It just will not move the file.
I have a script that was working before, but we recently changed the FTP location and is no longer working correctly. I have tried setting to passive mode and switching between ascii / binary with no luck.
Below is my script, is there something obvious I'm missing? Is there a way to easily identify the error? The specified directory has all permissions. It connects just fine and I can list the directory contents and see all the folders correctly...just doesn't upload.
$file = $createdAt.".txt";
$fp = fopen('exportorder/'.$file, 'r');
$conn_id = ftp_connect('ftp.location.com') or die("Couldn't connect to ftp.location.com");;
$login_result = ftp_login($conn_id, 'username', 'pass');
ftp_pasv($conn_id,TRUE);
ftp_chdir($conn_id, '/OTD-0000117');
if (ftp_fput($conn_id, 'exportorder/'.$file, $fp, FTP_BINARY)) {
echo "Successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
Thanks in advance!
Use ftp_put that will dump the file from source to target if there is no change between source and target file.
I'm trying to upload a file from my webserver to my game server through a script. The problem is that it can't find the directory.
The full directory is /174.34.132.106 port 27015/tf/addons/sourcemod/configs/tf2items.weapons.txt
This path didn't work so I asked the hosting about it and they insisted that /tf/addons/sourcemod/configs/tf2items.weapons.txt is the correct path but this doesn't work either. The game server is running on a windows server and i'm pretty sure the web server is running on linux. Is my code wrong, do I have to replace the spaces in the directory with %20. Thanks in advance!
$ftp_server="174.34.132.106";
$ftp_user_name="Username";
$ftp_user_pass="Password";
$remote_file = "tf2items.weapons.txt";
$file = "weapons/tf2items.weapons.txt";//tobe uploaded
if(!file_exists($file)) echo "The local file does not exist";
$conn_id = ftp_connect($ftp_server) or die('Unable to create the connection');
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_chdir($conn_id, "174.34.132.106 port 27015/tf/addons/sourcemod/configs/");
echo ftp_pwd($conn_id);
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
I noticed that the FTP server you're connecting to is using a non-standard port, so it's probably not making the connection. You need to specify the port in the ftp_connect, like so:
$ftp_server="174.34.132.106";
$ftp_port = "27015";
$ftp_user_name="username";
$ftp_user_pass="password";
$remote_file = "tf/addons/sourcemod/configs/tf2items.weapons.txt";
$file = "weapons/tf2items.weapons.txt";//tobe uploaded
// set up basic connection
$conn_id = ftp_connect($ftp_server,$ftp_port) or die('Unable to create the connection');
The die() will stop the script if it's unable to make the connection. You can add the same after your ftp_login line to make sure that it's actually logging in.
Edit To make sure your file exists, try this above the ftp_put line.
if(!file_exists($file)) echo "The local file does not exist";
Edit 2 After reading down on ftp_put, it says that the remote_file does not support directories. You'll need to use ftp_chdir first.
ftp_chdir($conn_id, "tf/addons/sourcemod/configs/");
Then for remote_file, use just tf2items.weapons.txt. You can still use filepaths for the local file.
If that's a Linux server ensure that you use correct case for directory names.
"tf/addons/sourcemod/configs" is not the same as "TF/addons/sourcemod/configs";
Just now I got an error with my FTP file upload part. I am not able to upload a file via ftp using PHP. the code which I entered is as follows :
<?php
$conn_id = ftp_connect(localhost);
$login_result = ftp_login($conn_id, 'newuser', 'wampp') or die("Could Not Connect To FTP Server");
$image = $_FILES['image']['tmp_name'];
$upload = ftp_put($conn_id, 'sri/image.jpg', $image, FTP_ASCII);
?>
The error that it shows is as follows :
Warning: ftp_put() [function.ftp-put]: Filename invalid in D:\xampp\htdocs\mycloud\edit.php on line 7
Please help me out of this stuff.
I think the process of uploading files via FTP has to be:
Connect to FTP Server
Login to the FTP Server (if applicable)
Change to the right directory - (I believe you need to do this before attempting to upload the file in the sri folder). So you will need to go to the sri folder.
Upload the file (so in your case it should be image.jpg only NOT sri/image.jp )
and then close the connection to the FTP Server.
To change to current directory to the right directory, I think you need to do the following:
if(ftp_chdir($conn_id, "sri"))
{
echo "Current directory is now: " . ftp_pwd($conn_id) ;
}
else
{
echo "Error could not change directory";
}
More info on changing directories