1

I have a simple web hosting, on SourceForge. All web hosting on SourceForge uses SFTP.

Now, I want to get a file on a other server (I have no administrative permission; but, I can view it in web browser normally. Such as: http://data.example.com/videos/fun.mp4.) to my web hosting on SourceForge (The hosting structure is: /home/project-web/my-own-project/htdocs/my-folder).

I have read these answers on many questions, like:

I have tried with all the answers. It displayed the succeed message; but, there is no file on my server.


Then, I have tried with changing CHMOD to 777 (I understand that it is damage; so, I tried for testing only). And, there is no file too; in other answer, there is an empty file.

I have use phpinfo(); for checking the cURL, it is (always) enabled.


Can you tell me what is wrong in my doing list. And, please show me: "How to upload file from URL to SourceForge web hosting, by PHP?".


My question is not duplicated with existed questions on Stack Overflow.
I have used a 20 KB file for testing; but, the uploaded file on my server is empty.

Community
  • 1
  • 1
lvk
  • 131
  • 6
  • did you test writing an empty file to the web server hosting, if you can write the file at all to your file structure. e.g. try file_put_contents('testfile.txt', 'success'); Put the code in php file and Run that php file. Look for testfile.txt in same directory where php file is located. If you can write the file at all, then it can be fixed. – Aditya May 28 '16 at 03:50
  • Ok. And I forgot to ask, if you have verified in php.ini `allow_url_fopen` is on? Having said you have tested with 20KB file, do you mean to say, that you downloaded 20 kB file from some url to hosting site? – Aditya May 28 '16 at 04:06
  • Please check if this helps. – Aditya May 28 '16 at 04:45

1 Answers1

3

Updated as per Use-Policy: https://sourceforge.net/p/forge/documentation/Project%20Web%20and%20Developer%20Web/#outbound-connectivity

Due to past abuse, outbound access to other hosts from the web servers is strictly prohibited, and is blocked by firewall rules. This includes access to other SourceForge.net hosts; the only exceptions to this policy are access to our project database servers and authorized outgoing emails. SCM server access is not available from the project web servers. Any content needed from other SourceForge.net hosts should be retrieved and stored as a file or database entry that may then be accessed from scripts on the project web servers. While our PHP install (and other languages) include support for things like LDAP, IMAP and Postgres, we do not permit inbound or outbound connectivity using these protocols. These components are included so third-party code may be kept stock when being deployed on SourceForge.net web servers; and to support the testing of project code which requires these functions.

So the ability to connect to external hosts is blocked by a firewall and is not possible.


Please post your phpinfo() output in your question. Specifically the system details (top section), core, curl, sockets, and standard section values (leave out any confidential info like database passwords/connections).

There are lots of things that could prevent it from saving, user permissions (on the executable), server configuration, suPHP (sandboxed user), chrooted web directory, php configuration, etc. We would need to see the actual code you used to diagnose your specific issue.

As for something to try, use this code.

<?php

if (file_put_contents('/home/project-web/my-own-project/htdocs/my-folder/test.txt', 'Hello World!')) {
   echo 'File Saved Successfully!';
}

if test.txt exists and says Hello World! when you download and open it from SFTP, try the below.

Also most SFTP clients need to be refreshed after new content has been added to the server. So please ensure you have refreshed your SFTP client.


<?php

umask(0000); //this sets everything this script interacts with as everyone writable/executable 
//(same as chmod(0777))

$output_path = '/home/project-web/my-own-project/htdocs/my-folder';
$out_file = 'fun.mp4';
$source = file_get_contents('http://data.example.com/videos/fun.mp4');
if (empty($source)) {
  die('No Content Received');
}
if (!@mkdir($output_path, 0777, true) && !is_dir($output_path)){
   die('Unable to create destination directory!');
}
if (file_put_contents($output_path . '/' . $out_file, $source)) {
   echo 'File Saved Successfully!';
}

I tested the above on my webserver with a 5 MB MP4 (specifically http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 - first google result for an mp4 download) and it worked fine.

This would be a last ditch effort to get it to work.

Will B.
  • 17,883
  • 4
  • 67
  • 69