Writing a File to a local share from a webserver - php

I am trying to write a file to a local share using PHP and a webserver. The origin of the file is the webserver ubuntu01 and a share on my local machine 7PD01-2012 is where the file is to be written. The path "ftp://ryan:pass#7PD01-2012//file.txt" resolves when I put it in a web browser and displays the file contents. There does not seem to be a permissions issue. I am able to ping the webserver from the client and the client from the webserver. FTP is installed on my ubuntu webserver and Filezille ftp Server is installed on the client. Using filezilla or the browser I am able to ftp to both locations. I have setup firewall rules on the webserver and updated the /etc/hosts file. Any ideas what could be causing these errors?
$fileName = "ftp://ryan:pass#7PD01-2012//file.txt";
is_dir($fileName);
if (($myfile = fopen($fileName, "w")) === false) { //open the file
//if unable to open throw exception
throw new RuntimeException("Could Not Open File Location on Server.");
}
( ! ) Warning: is_dir(): connect() failed: Connection timed out in /var/www/html/CDprinter/processor.php on line 143
( ! ) Warning: fopen(): connect() failed: Connection timed out in /var/www/html/CDprinter/processor.php on line 144
( ! ) Warning: fopen(ftp://...#10.162.12.130//file.txt): failed to open stream: operation failed in /var/www/html/CDprinter/processor.php on line 144

Related

Getting files from sftp server using php and ssh2

Recently, for a project, i have been trying to get a few files from a sftp webserver using ssh2 extension and php. So far i've managed to connect to the server and list all the files on a specific directory, but when i try to get them with ssh2_scp_recv i allways get
"Warning: ssh2_scp_recv(): Unable to receive remote file in ..." . I've used another implementation, that worked, with fread, but the transfer speed are too slow, and i need some more speed.
In the implementation i've been working on i tried using the refered function inside a loop passing the file names / paths as:
ssh2_scp_recv($connection, "/download/file.json", "C:\Users\User\file.json");
but no luck. Does anyone know of a better way to achieve the goal or to surpass this problem?
Edit:
<?php
$url = 'server.url.com';
$port = 22;
$username = "username";
$password = "password";
// Make our connection
$connection = ssh2_connect($url);
// Authenticate
if (!ssh2_auth_password($connection, $username, $password)) throw new Exception('Unable to connect.');
// Create our SFTP resource
if (!$sftp = ssh2_sftp($connection)) throw new Exception('Unable to create SFTP connection.');
$localDir = 'C:\Users\User';
$remoteDir = '/download';
// download all the files
$files = scandir('ssh2.sftp://' . $sftp . $remoteDir);
if (!empty($files)) {
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
ssh2_scp_recv($connection, "$remoteDir/$file", "$localDir\\$file");
}
}
}
?>
This is the code i'am using, and i get this output:
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
Warning: ssh2_scp_recv(): Unable to receive remote file in C:\xampp\htdocs\teste1.php on line 26
As i was saying i suspect the problem may be the localdir path as i am using windows, but not sure as i tryed many alternatives and none worked.

how to open gnome-terminal by using php script

When i open gnome-terminal from my php script it errors :
"gdk_mir_display_open
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Failed to parse arguments: Cannot open display:"
How to resolve it please suggest me.

Warning: require_once(/home/content/28/11459128/html/system/startup.php): failed to open stream:

I have recently taken backup for my website and wanted to open with xampp on local host but it is showing following errors:
Warning: require_once(/home/content/28/11459128/html/system/startup.php): failed to open
stream: No such file or directory in C:\xampp\htdocs\myfolder\index.php on line 26
Fatal error: require_once(): Failed opening required
'/home/content/28/11459128/html/system/startup.php' (include_path='.;C:\xampp\php\PEAR') in
C:\xampp\htdocs\myfolder\index.php on line 26
Can any one help me with this issue.
Thanks,
GC
You need to change all the PATH in your project according to your local machine, or there must a variable in your config file i.e Path to project for local environment is C:/xampp/htdocs and for production server it must be /home/content/whatever. If it is not present you better create one.
I am pretty sure path won't start with / on Windows(local machine).

Windows composer install issue

I'm trying to install composer via the composer-setup.exe from http://getcomposer.org/download/ and I'm getting the following error:
Connection Error [ERR_CONNECTION]: Unable to connect to getcomposer.org
Request to https://getcomposer.org/installer failed with errors: SSL:
The operation completed successfully. . Send of 25 bytes failed with
errno=10054 An existing connection was forcibly closed by the remote
host. . Send of 23 bytes failed with errno=10054 An existing
connection was forcibly closed by the remote host. . Send of 2 bytes
failed with errno=10054 An existing connection was forcibly closed by
the remote host. . Failed to open stream: HTTP request failed!
I tried disabling my antivirus/firewall but I keep on getting the same error. I searched google but couldn't resolve this. Any help here? Thanks.
Is SSL enabled in the correct php.ini?
If the installation approach via the windows executable fails,
you might switch to just downloading the composer.phar to your PHP dir, e.g. C:\php\composer.phar.
Then add composer.bat file inside the C:\php folder which forwards commands to the PHAR file:
#ECHO OFF
php "%~dp0composer.phar" %*
Also add the path to your php directory (e.g. C:\php) to the Path in your System variables. This result in a global installaton of composer. You can call composer on any project path.

404 needed instead of Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 on pages with XX0 permissions

Using PHP Version 5.3.15 with Apache 2 on a Mac Web Server.
A while back (it's been years) I had this working right and I have no idea what has changed so I was wondering if anyone has a solution.
What I would like to happen is when a file with a "0" permission in the everyone slot (ie 770, 640, etc) is called by the browser from our server the user gets a 404 or page not found. Right now if a file with 0 for everyone is opened the following is displayed in the browser:
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Fatal error: Unknown: Failed opening required '/path to site/www/membership/donate_vehicle.php' (include_path='.:') in Unknown on line 0
Example: http://wfsu.org/membership/donate_vehicle.php
Does anyone know how to make a 404 page there instead? It's got to be a configuration or something, because like I said, it was this way on our old server, which was an older Mac server running an older version of PHP and Apache, just not sure what.
Thanks
$myfile = '/path/to/file.php';
if( file_exists($myfile) && is_readable($myfile) ) {
require($myfile);
} else {
// do 404 stuff
}

Categories