• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

How to remote upload?

Ruriko

New Member
Hi is there a script that can remote upload from another server? I'm not looking for a file host script. I need one with queue feature
 
As in upload to a different server? I don't think so. It wouldn't be that hard to do.
 
PHP:
<?php
if( function_exists( 'ftp_connect' ) )
{
	class FTP_Transfer
	{
		var $errors, $success ;
			
		function FTP_Transfer(
			$infile, 
			$outpath, 
			$hostname,
			$username,
			$password,
			$timeout = 5,
			$port = 21,
			$unlink = false,
			$binary = 0
		)
		{
			if( ( $this->server = ftp_connect( $hostname, $port, $timeout ) ) )
			{
				if( @ftp_login( $this->server, $username, $password ) === true )
				{
					if( ( $handle = fopen( $infile, $binary ? 'rb' : 'r' ) ) )
					{
						if( ftp_fput( $this->server, $outpath, $handle, $binary ? FTP_BINARY : FTP_ASCII  ) )
						{
							$this->success[ ] = sprintf(
								"Uploaded input file '%s' to '%s' via FTP @ %s:%d", $infile, $outpath, $hostname, $port
							);
						
							fclose( $handle );
						
							if( $unlink )
							{
								if( @unlink( $infile ) === false )
								{
									$this->errors[ ] = sprintf(
										"Failed to delte input file '%s' from local filesystem", $infile
									);
								}
								else $this->success[ ] = sprintf(
									"Removed input file '%s' from local filesystem", $infile
								);
							}
						}
						else $this->errors[ ] = sprintf( 
							"Failed to upload input file '%s' to output path '%s' via FTP @ %s:%d", $infile, $outpath, $hostname, $port
						);
					}
					else $this->errors[ ] = sprintf(
						"Failed to open input file '%s' for reading", $infile
					);
				}
				else $this->errors[ ] = sprintf(
					"Failed to login to FTP server @ %s:%d as %s with supplied password", $hostname, $port, $username
				);
			}
			else $this->errors[] = sprintf(
				"Failed to connect to FTP server @ %s:%d", $hostname, $port
			);
		}
	}
}

if( $_POST )
{
	$errors = array( ) ;
	$success = array( ) ;

	if( class_exists( 'FTP_Transfer' ) )
	{
		if( $_FILES['infile'] )
		{
			if( $_POST['hostname'] )
			{
				if( $_POST['username'] )
				{
					if( $_POST['password'] )
					{
						if( is_uploaded_file( $_FILES['infile']['tmp_name'] ) )
						{
							if( move_uploaded_file( $_FILES['infile']['tmp_name'], $_FILES['infile']['name'] ) )
							{
								$infile = $_FILES['infile']['name'];
								$outpath = $_POST['outpath'] ? sprintf( '%s/%s', $_POST['outpath'], $_FILES['infile']['name'] ) : "/{$_FILES['infile']['name']}" ;
								$hostname = $_POST['hostname'] ? $_POST['hostname'] : 'localhost' ;
								$username = $_POST['username'] ? $_POST['username'] : '' ;
								$password = $_POST['password'] ? $_POST['password'] : '' ;
								$timeout = $_POST['timeout'] ? $_POST['timeout'] : 5 ;
								$port = $_POST['port'] ? $_POST['port'] : 21 ;
								$unlink = $_POST['unlink'] ? $_POST['unlink'] : 0 ;
								$binary = $_POST['binary'] ? $_POST['binary'] : 0 ;

								$xfer = new FTP_Transfer( $infile, $outpath, $hostname, $username, $password, $timeout, $port, $unlink, $binary );
								
								if( $xfer->errors ) $errors = array_merge( $errors, $xfer->errors );
								if( $xfer->success ) $success = array_merge( $success, $xfer->success );
							}
							else $errors[ ] = "Possible security breach, bailing out";
						}
						else $errors[ ] = "Possibly security breach, bailing out";
					}
					else $errors[ ] = "Please enter your FTP password";
				}
				else $errors[ ] = "Please enter your FTP username";
			}	
			else $errors[ ] = "Please enter your FTP hostname";
		}
		else $errors[ ] = "Please select a file to upload";
	}
	else $errors[ ] = "Required class 'FTP_Transfer' not available";
}
?>
<html>
	<head>
		<title>Transfer file to FTP server</title>
		<style type="text/css">
			*{
				margin: 4px;
				padding: 0px;
			}
		</style>	
	</head>
	<body>
		<?php if( $errors ): foreach( $errors as $error ) printf( "<div class=\"error\">%s</div>\n", $error ); endif; ?>
		<?php if( $success ): foreach( $success as $message ) printf( "<div class=\"message\">%s</div>\n", $message ); endif; ?>

		<form enctype="multipart/form-data" action="" method="POST">
    		<input type="hidden" name="MAX_FILE_SIZE" value="9999999999999" />
    		<p>Input File: <input name="infile" type="file" /></p>
		<p>FTP Hostname: <input type="text" name="hostname" value="<?php echo $_POST['hostname'] ?>"/></p>
		<p>FTP Username: <input type="text" name="username" value="<?php echo $_POST['username'] ?>"/></p>
		<p>FTP Password: <input type="password" name="password" value="<?php echo $_POST['password'] ?>"/></p>
		<p>FTP Port: <input type="text" name="port" value="<?php echo $_POST['port'] ? $_POST['port'] : 21 ; ?>"/></p>
		<p>FTP Path: <input type="text" name="outpath" value="<?=$_POST['outpath'] ?>"/></p>
		<p><input type="checkbox" value="1" name="binary" <?php if( $_POST['binary'] ): ?>checked<?php endif; ?>/> Binary mode transfer</p>
	    	<p><input type="checkbox" value="1" name="unlink" <?php if( $_POST['unlink'] ): ?>checked<?php endif; ?>/> Delete local copy</p>
		<input type="submit" value="Transfer" />
		</form>
	</body>
</html>

Got bored, could do with tweaking / styling ... maybe someone else can do that bit ...
 
PHP:
<?php
if( function_exists( 'ftp_connect' ) )
{
	class FTP_Transfer
	{
		var $errors, $success ;
			
		function FTP_Transfer(
			$infile, 
			$outpath, 
			$hostname,
			$username,
			$password,
			$timeout = 5,
			$port = 21,
			$unlink = false,
			$binary = 0
		)
		{
			if( ( $this->server = ftp_connect( $hostname, $port, $timeout ) ) )
			{
				if( @ftp_login( $this->server, $username, $password ) === true )
				{
					if( ( $handle = fopen( $infile, $binary ? 'rb' : 'r' ) ) )
					{
						if( ftp_fput( $this->server, $outpath, $handle, $binary ? FTP_BINARY : FTP_ASCII  ) )
						{
							$this->success[ ] = sprintf(
								"Uploaded input file '%s' to '%s' via FTP @ %s:%d", $infile, $outpath, $hostname, $port
							);
						
							fclose( $handle );
						
							if( $unlink )
							{
								if( @unlink( $infile ) === false )
								{
									$this->errors[ ] = sprintf(
										"Failed to delte input file '%s' from local filesystem", $infile
									);
								}
								else $this->success[ ] = sprintf(
									"Removed input file '%s' from local filesystem", $infile
								);
							}
						}
						else $this->errors[ ] = sprintf( 
							"Failed to upload input file '%s' to output path '%s' via FTP @ %s:%d", $infile, $outpath, $hostname, $port
						);
					}
					else $this->errors[ ] = sprintf(
						"Failed to open input file '%s' for reading", $infile
					);
				}
				else $this->errors[ ] = sprintf(
					"Failed to login to FTP server @ %s:%d as %s with supplied password", $hostname, $port, $username
				);
			}
			else $this->errors[] = sprintf(
				"Failed to connect to FTP server @ %s:%d", $hostname, $port
			);
		}
	}
}

if( $_POST )
{
	$errors = array( ) ;
	$success = array( ) ;

	if( class_exists( 'FTP_Transfer' ) )
	{
		if( $_FILES['infile'] )
		{
			if( $_POST['hostname'] )
			{
				if( $_POST['username'] )
				{
					if( $_POST['password'] )
					{
						if( is_uploaded_file( $_FILES['infile']['tmp_name'] ) )
						{
							if( move_uploaded_file( $_FILES['infile']['tmp_name'], $_FILES['infile']['name'] ) )
							{
								$infile = $_FILES['infile']['name'];
								$outpath = $_POST['outpath'] ? sprintf( '%s/%s', $_POST['outpath'], $_FILES['infile']['name'] ) : "/{$_FILES['infile']['name']}" ;
								$hostname = $_POST['hostname'] ? $_POST['hostname'] : 'localhost' ;
								$username = $_POST['username'] ? $_POST['username'] : '' ;
								$password = $_POST['password'] ? $_POST['password'] : '' ;
								$timeout = $_POST['timeout'] ? $_POST['timeout'] : 5 ;
								$port = $_POST['port'] ? $_POST['port'] : 21 ;
								$unlink = $_POST['unlink'] ? $_POST['unlink'] : 0 ;
								$binary = $_POST['binary'] ? $_POST['binary'] : 0 ;

								$xfer = new FTP_Transfer( $infile, $outpath, $hostname, $username, $password, $timeout, $port, $unlink, $binary );
								
								if( $xfer->errors ) $errors = array_merge( $errors, $xfer->errors );
								if( $xfer->success ) $success = array_merge( $success, $xfer->success );
							}
							else $errors[ ] = "Possible security breach, bailing out";
						}
						else $errors[ ] = "Possibly security breach, bailing out";
					}
					else $errors[ ] = "Please enter your FTP password";
				}
				else $errors[ ] = "Please enter your FTP username";
			}	
			else $errors[ ] = "Please enter your FTP hostname";
		}
		else $errors[ ] = "Please select a file to upload";
	}
	else $errors[ ] = "Required class 'FTP_Transfer' not available";
}
?>
<html>
	<head>
		<title>Transfer file to FTP server</title>
		<style type="text/css">
			*{
				margin: 4px;
				padding: 0px;
			}
		</style>	
	</head>
	<body>
		<?php if( $errors ): foreach( $errors as $error ) printf( "<div class=\"error\">%s</div>\n", $error ); endif; ?>
		<?php if( $success ): foreach( $success as $message ) printf( "<div class=\"message\">%s</div>\n", $message ); endif; ?>

		<form enctype="multipart/form-data" action="" method="POST">
    		<input type="hidden" name="MAX_FILE_SIZE" value="9999999999999" />
    		<p>Input File: <input name="infile" type="file" /></p>
		<p>FTP Hostname: <input type="text" name="hostname" value="<?php echo $_POST['hostname'] ?>"/></p>
		<p>FTP Username: <input type="text" name="username" value="<?php echo $_POST['username'] ?>"/></p>
		<p>FTP Password: <input type="password" name="password" value="<?php echo $_POST['password'] ?>"/></p>
		<p>FTP Port: <input type="text" name="port" value="<?php echo $_POST['port'] ? $_POST['port'] : 21 ; ?>"/></p>
		<p>FTP Path: <input type="text" name="outpath" value="<?=$_POST['outpath'] ?>"/></p>
		<p><input type="checkbox" value="1" name="binary" <?php if( $_POST['binary'] ): ?>checked<?php endif; ?>/> Binary mode transfer</p>
	    	<p><input type="checkbox" value="1" name="unlink" <?php if( $_POST['unlink'] ): ?>checked<?php endif; ?>/> Delete local copy</p>
		<input type="submit" value="Transfer" />
		</form>
	</body>
</html>

Got bored, could do with tweaking / styling ... maybe someone else can do that bit ...

He probably meant it so that people wouldn't have to know what the ftp server and other stuff was.
 
They wouldn't have to, you could change the code that creates the FTP_Transfer object ... tbh the user is asking too much for free just thought I'd get the ball rolling with something ...
 
They wouldn't have to, you could change the code that creates the FTP_Transfer object ... tbh the user is asking too much for free just thought I'd get the ball rolling with something ...

and a damn nice job you did Joe. once again. :D
 
Err thank you for bumping a 1month old topic but unfortunately all of you misunderstood what I wanted. What I meant is I want to transfer from server to server not my comp to server. Anyway I found a script called Rapid Leech which does the job I want except it doesn't have queue feature =[
 
Back
Top