Grabbing Files from other server

Discussion in 'PHP' started by phantomddl, Sep 26, 2007.

  1. #1
    i need a script which will grab many files at once from other server to my server
    there will be a text form where i can type urls line by line and one input form that i can specify, to which folder it will upload the files
    i hope you get what i mean.. i want a script that will transfer many files to a specific folder i choose each time.
    i can pay a little amount for that if required. thanks
     
    phantomddl, Sep 26, 2007 IP
  2. SoniCute

    SoniCute Active Member

    Messages:
    585
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #2
    If you have root access (VPS or Dedicated) you dont need a script,just use vi to create a list downloaded files and use wget to execute the list.
     
    SoniCute, Sep 27, 2007 IP
  3. phantomddl

    phantomddl Well-Known Member

    Messages:
    2,856
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    160
    Articles:
    15
    #3
    i am making a gallery script that will index photos from folders and show them on website, but i don't want to connect to ssh each time i wanna do it and i don't wanna download pictures to my computer then upload them to ftp cuz of my slow internet connection
    thanks for the suggestion
     
    phantomddl, Sep 27, 2007 IP
  4. sky22

    sky22 Guest

    Messages:
    59
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This any good?

    <?php
    function get_url( $url )
    {
    	$contents = '';
    
    	ini_set( 'user_agent', 'User-Agent: PHPGet/1.0' );
    	if( ( $fp = fopen( $url, 'r' ) ) )
    	{
    		for( ;($data = fread( $fp, 1024 ) ); )
    			$contents .= $data;
    
    		fclose( $fp );
    	}
    	elseif( function_exists( 'curl_init' ) )
    	{
    		$ch = curl_init( );
    
    		curl_setopt( $ch, CURLOPT_URL, $url );
    		curl_setopt( $ch, CURLOPT_HEADER, 0 );
    		curl_setopt( $ch, CURLOPT_USERAGENT, 'User-Agent: PHPGet/1.0' );
    		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    
    		$contents .= curl_exec( $ch );
    
    		curl_close( $ch );
    	}
    	elseif( ( $url_info = parse_url( $url ) ) )
    	{
    		if( $url_info['scheme'] == 'https' )
    			$fp = fsockopen( 'ssl://' . $url_info['host'], 443, $errno, $errstr, 30);
    		else
    			$fp = fsockopen( $url_info['host'], 80, $errno, $errstr, 30);
    
    		if( !$fp )
    			return false;
    
    		$out = 'GET ' . (isset($url_info['path'])? $url_info['path']: '/') .
    			(isset($url_info['query'])? '?' . $url_info['query']: '') . " HTTP/1.0\r\n";
    		$out .= "Host: {$url_info['host']}\r\n";
    		$out .= "User-Agent: PHPGet/1.0\r\n";
    		$out .= "Connection: Close\r\n\r\n";
    
    		fwrite($fp, $out);
    		for( ;!feof( $fp ); )
    			$contents .= fgets($fp, 128);
    
    		list($headers, $content) = explode( "\r\n\r\n", $contents, 2 );
    
    		return $content;
    	}
    	else
    		return false;
    
    	return $contents;
    }
    
    if( $_POST['urls'] )
    {
    	$ourput_dir = $_POST['folder'];
    
    	$urls = explode( "\r\n", $_POST['urls'] );
    
    	for($i=0; isset( $urls[$i] ); $i++)
    	{
    		$contents = get_url( $urls[$i] );
    		$name = explode( '/', $urls[$i] );
    
    		$fp = fopen( $ourput_dir . $name[count($name)-1], 'w' );
    		fwrite( $fp, $contents );
    		fclose( $fp );
    	}
    }
    else
    {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    URLS: (line by line) <textarea name="urls"></textarea><br />
    Folder to save to: <input type="text" name="folder" value="./folderto/" /><br />
    <input type="submit" value="get" />
    </form>
    <?php
    }
    
    ?>
    PHP:
    Sky22
     
    sky22, Sep 27, 2007 IP
    phantomddl likes this.
  5. phantomddl

    phantomddl Well-Known Member

    Messages:
    2,856
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    160
    Articles:
    15
    #5
    yes thats what i exactly wanted! :)
    rep added ^^
     
    phantomddl, Sep 27, 2007 IP