Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Merging two server to server transfer scripts ?
Old 04-26-2008, 06:16 PM Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
Hi

i had used these two scripts named "File Snatcher" and "Server to Server File Transfer 2".

File Snatcher while being a typical file snatching script is not well written and usually it is not able to get file size for the files, if the url contains redirection. On the other hand, SST is a great script which has a 100% success rate towards downloading files from other servers. But it has a restriction of 5 mb download allowed only.

The file snatcher script doesnt have any such restriction but its limit is the php timeout of the site only. But its not useful as its never able to detect the files on the other server. I was hoping and wished that somehow the SST script could be edited and that particular restriction removed. However, i am a noob so im really very helpless. Please help me in this thing. I am posting copies of both the scripts below, please help me
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-26-2008, 06:21 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
File Snatcher script


Index.php (The file which is to be run through the browser) ::

PHP Code:
<?php
define
('_ALLOWINCLUDE',0);
include 
'settings.php';
$version '2.8 Beta 3';
//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////
if (function_exists('curl_init'))
{
$snatch_system 'curl';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>File Snatcher <?php echo $version?> - &copy; http://noveis.net</title>
<style type="text/css">
iframe {
border:none;
width:600px;
height:100px;
overflow:hidden;
}
div.p3news_bar {
margin-top:2px;
height:16px;
background-color:#ab4a37;
border-bottom:1px solid #5f1000;
border-right:1px solid #af1d00;
color:#ffffff;
text-align:right;
font-weight:bold;
font-size:12px;
}
</style>
</head>
<body>
<div id="main">
<?php
$submit 
$_POST['submit'];
$file_size $_GET['fs'];
$ds $_GET['ds'];
if (
$_GET['fs'] == true)
{
$ds_fs filesize($ds);
$progress round(($ds_fs/$file_size)*1002);
if(
$progress >= 100)
{
$done 1;
}
else
{
$done 0;
}
 
if(
$_GET['done'] == 0)
{
echo 
'<meta http-equiv="refresh" content="'$refresh_time .';index.php?&done='$done .'&amp;fs='.$file_size.'&amp;ds='.$ds.'">';
}
echo 
'<div class="p3news_bar" style="width:'$progress .'%;">'$progress .'% copied</div>';
echo 
'<p>Copied 'round($ds_fs/10242) .' of 'round($file_size/10242) .'KB</p>';
}
elseif (
$submit == true)
{
if (isset(
$password))
{
if (
$_POST['password'] != $password)
{
die(
'<p><strong>Password incorrect!</strong></p>');
$error true;
}
}
 
if (!
file_exists($defaultDest))
{
mkdir($defaultDest);
}
chdir($defaultDest);
$sizelimit_kb $sizelimit;
$sizelimit $sizelimit 1024;
 
$file rawurldecode($_POST['file']);
 
$uploadfile explode('/'$file);
$filename array_pop($uploadfile);
$newfilename $_POST['new'];
if(
strstr($newfilename'/'))
{
$new_path explode('/'$newfilename);
array_pop($new_path);
$new_path implode('/'$new_path);
if(!
file_exists($new_path))
{
mkdir($new_path);
echo 
'<p>Making directory "'$new_path .'"</p>';
}
}
 
$newfilename str_replace('*'$filename$newfilename);
if (!
$newfilename)
{
$newfilename $filename;
}
 
if (!isset(
$file))
{
echo 
'<p><strong>Please enter a URL to retrieve file from!</strong></p>';
$error true;
}
 
if (!isset(
$newfilename))
{
echo 
'<p><strong>Please enter a new file name!</strong></p>';
$error true;
}
 
if (
$error == false)
{
$dest $defaultDest;
$ds = array($dest'/'$newfilename);
$ds implode(''$ds);
$newname_count 0;
if (
file_exists($ds))
{
echo 
'<p><strong>File already exists!</strong></p>';
//Dev Add - next 1 line
$new_name_needed true
$newname_count++;
$newfile = array($newname_count$newfilename);
$newfile implode('~'$newfile);
$newfile_ds = array($dest'/'$newfile);
$newfile_ds implode(''$newfile_ds);
while(
$renamed == false)
{
if (
file_exists($newfile_ds))
{
$newname_count++;
$newfile = array($newname_count$newfilename);
$newfile implode('~'$newfile);
$newfile_ds = array($dest'/'$newfile);
$newfile_ds implode(''$newfile_ds);
}
else
{
$renamed true;
}
}
$newfilename $newfile;
$ds $newfile_ds;
echo 
'<p>New file name is <strong>'.$newfile.'</strong>.</p>';
}
echo 
'<p><strong>Copying...</strong></p>';
if (
$snatch_system == 'curl')
{
// Start Remote File Size //
ob_start();
$chF curl_init($file);
curl_setopt($chFCURLOPT_HEADER1);
curl_setopt($chFCURLOPT_NOBODY1);
 
$ok curl_exec($chF);
curl_close($chF);
$head ob_get_contents();
ob_end_clean();
 
$regex '/Content-Length:\s([0-9].+?)\s/';
$count preg_match($regex$head$matches);
 
if(
$matches[1] > 0)
{
if (isset(
$matches))
{
$file_size $matches[1];
$file_size_kb round($file_size/10242);
echo 
'<p>Size of file to be copied: '.$file_size_kb.'KB.</p>';
}
else
{
$no_filesize true;
unset(
$file_size);
}
}
else
{
echo 
'<p>Could not get file size.</p>';
}
if(
$file_size $sizelimit && $sizelimit 0)
{
echo 
'<p>File size is too large.<br />Max file size is '.$sizelimit_kb.'KB.</p>';
$copy_fail true;
}
 
if(
$copy_file == false && $file_size 0)
{
echo 
'<iframe name="progress"
src="index.php?fs='
.$file_size.'&amp;ds='.$ds.'">
</iframe>'
;
$ch curl_init($file);
$fp fopen($ds'w');
curl_setopt($chCURLOPT_FILE$fp);
curl_setopt($chCURLOPT_HEADER0);
curl_exec($ch);
$curl_info curl_getinfo($ch);
curl_close($ch);
fclose($fp);
}
}
else
{
if (!
copy($file$ds))
{
echo 
'<p>Was unable to copy <a href="'.$file.'">'.$file.'</a><br />See if your path and destination are correct.</p>';
$copy_fail true;
}
}
 
if (
$copy_fail == false)
{
if (
$sizelimit && filesize($ds) > $sizelimit)
{
echo 
'<p><strong>File is too large.</strong>';
unlink($ds);
}
else
{
echo 
'<p><strong>Copy successful!</strong></p>';
echo 
'<p><a href="'.$URLDest.'/'.$newfilename.'">Click here for file</a></p>';
if (
$snatch_system == 'curl')
{
$size_dl round($curl_info['size_download']/10242);
$speed_dl round($curl_info['speed_download']/10242);
echo 
'<p>Downloaded '.$size_dl.'KB in '.$curl_info['total_time'].' seconds.<br />With an average download speed of '.$speed_dl.'KB/s.';
}
}
}
}
}
if (
$_GET['fs'] == false)
{
$self $_SERVER['PHP_SELF'];
echo 
'<form method="POST" action="'.$self.'">';
echo 
'<fieldset><legend>File Snatcher</legend>';
echo 
'<label for="file">Full path to file to copy</label>';
echo 
'<p>Example: http://foobar.com/image.png</p>';
echo 
'<p><input type="text" name="file" id="file" size="45" value=""></p>';
echo 
'<label for="new">New file name (Optional)</label><br />';
echo 
'<p>Example: image.png. Or you can specify a different path in relation to the default path, and you can use an asterix (*) to use the orginal file name. Example: new_folder/*</p>';
echo 
'<p><input type="text" name="new" id="new" size="45" value=""></p>';
if (isset(
$password))
{
echo 
'<label for="password">Password</label>';
echo 
'<p><input type="password" name="password" id="password" size="45" value=""></p>';
}
echo 
'<p><input name="submit" type="submit" id="submit" value="submit" accesskey="s"></p>';
echo 
'</fieldset></form>';
}
?>
</div>
</body>
</html>
Settings.php (The file containing all the settings) ::

PHP Code:
<?php
defined
('_ALLOWINCLUDE') or die();
// Default destination to copy files too NO TRAILING SLASH!!
// If it is complete path, file be copied there eg: /home/public_html/FOLDER (Linux) C:\htdocs\FOLDER (Windows)
// If it is just a folder it will be copied to the folder the script is in, but in the folder eg: /SnatcherFolder/FOLDER
$defaultDest '/home/examplene/public_html/snatched';
// If you want a password to be required
// Remember if you don't have a password anyone can copy a file to your server!
$password 'password'
 
// Operating System your SERVER Uses
//1 for Linux. 2 for Windows.
//I'm not sure but I think most Operating Systems other then Windows will use 1.
$os '1'
 
// URL to location of snatched files WITH OUT TRAILING SLASH
$URLDest 'http://example.net/snatched';
 
// Put a limit for file size in kilobytes (1024KB is 1MB)
// For unlimited put 0
// Example $sizelimit = 25;
$sizelimit 0;
?>

Last edited by Desi-Instincts; 04-27-2008 at 03:44 PM..
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-26-2008, 06:25 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
SST (Server to Server Transfer 2 Script)

script.inc.php ::

PHP Code:
<?
////////////////////////////////////////////////////////////////////////////////
// 
// Project : Server to Server Transfer [SST] 2 
// Filename : script.inc.php 
// Purpose : Javascript script library
// Version : 2.1 
// Author : James Azarja 
// 
function status($msg)
{
echo 
"<SCRIPT>document.form.status.value=\"$msg\";</SCRIPT>\n";
}
function 
changebg()
{
echo 
"<SCRIPT>document.bgColor=\"#B22222\";</SCRIPT>\n";
}
function 
progress($progress,$max)
{
echo 
"<SCRIPT>showprogress($progress,$max);</SCRIPT>\n";
}
?>
downloader.php ::
http://www.webmaster-talk.com/attach...1&d=1209245537

sst.php (The file which is to be run through the browser) ::
http://www.webmaster-talk.com/attach...1&d=1209245537
Attached Files
File Type: txt downloader.txt (13.6 KB, 10 views)
File Type: txt sst.txt (4.4 KB, 5 views)

Last edited by Desi-Instincts; 04-27-2008 at 03:44 PM..
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 03:58 AM Re: Merging two server to server transfer scripts ?
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
modify this line from the downloader.php
$maxsize=1048576*5;
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-27-2008, 03:39 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
Quote:
Originally Posted by solomongaby View Post
modify this line from the downloader.php
$maxsize=1048576*5;
I have already tried that . . . when i change the above mentioned value in your post to :
$maxsize=1073741824*5;

It increases the download limit till 15 MB or so..... but after that, when transferring any file, if it exceeds that value, it says :

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33293516 bytes) in /(my server's various directories)/downloader.php on line 166
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 03:41 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
Please its my request ... is there someone / anyone here who can help me ? Please help me its very urgent.
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 04:09 PM Re: Merging two server to server transfer scripts ?
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
that is due to the php configuration, increase the memory_limit setting in php.ini or directly in your php script by using the ini_set() function
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-27-2008, 04:15 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
Quote:
Originally Posted by solomongaby View Post
that is due to the php configuration, increase the memory_limit setting in php.ini or directly in your php script by using the ini_set() function
Sorry for being an irritating dumb noob.... but i didnt understand a word of what you said. Please i request could you assist in the coding thing ? Pretty please !
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 04:29 PM Re: Merging two server to server transfer scripts ?
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
sure for some TK )

Since i had explain this to a lot of people i have writen a post on my blog about it ... so it come easyer than writing the explanation every time.

Php has a limit of memory alocated for each script ( default 8MB, you can see it by putting the line phpinfo() in a test script ).
In your case the script goes over the limit because of the file your trying to download. To fix you must increase the memory_limit either in php.ini ( if you have acces ) or by adding the line ini_set('memory_limit','50MB'); to youre script.
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-27-2008, 04:39 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
where should i add this :

ini_set('memory_limit','50MB');

I mean in which line ? and in which file of the SST script ?
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 04:45 PM Re: Merging two server to server transfer scripts ?
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
downloader.php i would put in in the first lines
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-27-2008, 04:54 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
I added the mentioned line like this :
PHP Code:
<?
////////////////////////////////////////////////////////////////////////////////
//                                                                              
// Project   : Server to Server Transfer [SST] 2                                
// Filename  : downloader.php                                                   
// Purpose   : HTTP Downloader Implementation                                   
// Version   : 2.1                                                              
// Author    : James Azarja                                                     
//                                                                              
// How to:                                                                      
// -> Create the class                                                          
//      require_once("downloader.php");                                         
//      $downloader = new classDownloader;                                      
// -> Download a file                                                           
//      $downloader->download(<source_url>,<local_filename>)                    
//                                                                               
ini_set('memory_limit','50MB');
        include_once(
"script.inc.php");
        class 
classDownloader
        
{
                var 
$url            ""// (string) Requested URL
                
var $useragent      ""// (string) User Agent signature (act as ?)
                
var $referer        ""// (string) Referer URL
                
var $accept         ""// (string) Accept what ?
                
var $userid         ""// (string) HTTP Authentication Userid
                
var $password       ""// (string) HTTP Authentication Password
                
var $proxyaddr      ""// (string) Use Proxy ?
                
var $proxyport      ""// (string) Proxy port ?
                
var $contenttype    "";
                var 
$timeout        60;
                var 
$errorid        0;
                var 
$errormsg       "";
sst.php on executing says ::
Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 89780 bytes) in /(my server's directories)/downloader.php on line 168
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-27-2008, 05:19 PM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
I just changed the code to :: (had read it at another place)

<?
ini_set('memory_limit', -1);
////////////////////////////////////////////////////////////////////////////////
//
// Project : Server to Server Transfer [SST] 2
// Filename : downloader.php
// Purpose : HTTP Downloader Implementation
// Version : 2.1
// Author : James Azarja
//
// How to:
// -> Create the class
// require_once("downloader.php");
// $downloader = new classDownloader;
// -> Download a file
// $downloader->download(<source_url>,<local_filename>)
//

include_once(
"script.inc.php");


It started downloading well and continued till 70 MB, then the progress bar in IE 7 vanished but it was still showing "waiting for sst.php" is there a way to counter this problem ?
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 04:18 AM Re: Merging two server to server transfer scripts ?
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
i think this is due to the long time the script is running ... and not sending any responses ... wich makes the browser think the script has ended or has stuck .... try to echo something once a while ...
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-28-2008, 06:02 AM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
Does this have something to do with timeouts ?? If yes, then could you please tell me a way to counter this problem. . . .
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 06:04 AM Re: Merging two server to server transfer scripts ?
Novice Talker

Posts: 13
Trades: 0
BTW, there was a parameter, relating to downloader.php which was set to 60 secs or something, i changed it to 3600. But its not working, what should i do ?
Desi-Instincts is offline
Reply With Quote
View Public Profile
 
Old 04-28-2008, 09:46 AM Re: Merging two server to server transfer scripts ?
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
I had an ideea but this seem to be already added to the code. echoing a space as the file is being downloaded.
PHP Code:
while (!feof($sockethandle))
                                        {
                                                
$size strlen($result);
                                                if (
$size>$maxsize)
                                                {
                                                        
status("Content size is too big (maximum: $maxsize)");
                                                        return 
false;
                                                }
                                                
status("Downloading from server [".strlen($result)." bytes]");
                                                
$result.= fread($sockethandle,4096);
                                                if (
$result=="")
                                                { return 
false; }
                                                echo 
" ";
                                        } 
you could try to change from echo " "; to echo "."; this way you would see some progress on the screen
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to Merging two server to server transfer scripts ?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50883 seconds with 13 queries