The code below for ftp upload from remote machine to server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

The code below for ftp upload from remote machine to server

Post by basudeb »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I just use this code to upload a file from my remote machine($source_file )  to the specific server.

  But this code is ok upto the $login_result .

 When it execute the function ftp_put it gives the "Error";

 Give me a suggestion regarding the error message..

Code: Select all

<?php
 $server = 'SERVER_NAME'; //changed for this example
$user = 'USER_NAME'; //changed for this example
$pass = 'PAEEWORD'; //changed for this example




$source_file = 'E:FOLDER:FILE_NAME'; 

$destination_file ='DESTINATION_FOLDER'; 


// set up basic connection
$conn_id=ftp_connect($server);

//echo ftp_pwd($conn_id); 


// login with username and password
$login_result = ftp_login($conn_id, $user, $pass);


$abc=ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII) or die("Error");


// close the connection
ftp_close($conn_id); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
gavin1996
Forum Newbie
Posts: 22
Joined: Tue Jan 30, 2007 8:30 pm

Post by gavin1996 »

ftp_login is a Object????
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

The code below for ftp upload from remote machine to server

Post by basudeb »

1) No, here the ftp_login is the php in-built function. which is used to ftp login with a server.

2) I want to use FTP file/ Folder Uploading not any HTTP uploading.

3) So i also wanna know wheather is it possible to ftp uploading(file/folder) from a remote
client machine(as C:/documents/img.jpg) to a connected server ?

4) If possible then how?

5) Can any body post me the exact PHP code ?


Thanks
gavin1996
Forum Newbie
Posts: 22
Joined: Tue Jan 30, 2007 8:30 pm

Post by gavin1996 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


folder??? that's difficile/

try :

Code: Select all

<?php
$handle=opendir('.'); //input path

echo "folder handle: $handle\n";
echo "file:\n";
while ($file = readdir($handle)) {
echo "$file\n"; 


// upload file code .........

}
closedir($handle); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

The code below for ftp upload from remote machine to server

Post by basudeb »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I just use this code to upload a file from my remote machine($source_file ) to the specific server. 

But this code is ok upto the $login_result . 

When it execute the function ftp_put it gives the "Error"; 

Give me a suggestion regarding the error message.. 


Here the ftp_login is the php in-built function. which is used to ftp login with a server. 

 I want to use FTP file/ Folder Uploading not any HTTP uploading. 

 So i also wanna know wheather is it possible to ftp uploading(file/folder) from a remote 
client machine(as C:/documents/img.jpg) to a connected server ? 

 If possible then how? 

 Can any body post me the exact PHP code ?

Code: Select all

<!!----------This is my code ----------------!!!!!!!!>

<?php 
$server = 'SERVER_NAME'; //changed for this example 
$user = 'USER_NAME'; //changed for this example 
$pass = 'PAEEWORD'; //changed for this example 




$source_file = 'E:FOLDER:FILE_NAME'; 

$destination_file ='DESTINATION_FOLDER'; 


// set up basic connection 
$conn_id=ftp_connect($server); 

//echo ftp_pwd($conn_id); 


// login with username and password 
$login_result = ftp_login($conn_id, $user, $pass); 


$abc=ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII) or die("Error"); 


// close the connection 
ftp_close($conn_id); 
?>


Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
gavin1996
Forum Newbie
Posts: 22
Joined: Tue Jan 30, 2007 8:30 pm

Post by gavin1996 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_user\n";
}
?>

But..... is there exist a FTP server on your website Server????


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

Post by basudeb »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?php 
$ftp_server = "ftp.example.com"; 
$ftp_user = "foo"; 
$ftp_pass = "bar"; 

// set up a connection or die 
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// try to login 
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) { 
echo "Connected as $ftp_user@$ftp_server\n"; 
} else { 
echo "Couldn't connect as $ftp_user\n"; 
} 
?>


Yes when i use your code its ok amd shows me the message "Connected as $ftp_user@$ftp_server\n".



Upto that my code is also ok.. Now when i entire the ftp_put it doesn't work.

It gives the "ERROR"

I also give my code .

Code: Select all

<?php


$source_file = 'E:FOLDER:FILE_NAME'; 

$destination_file ='DESTINATION_FOLDER'; 




$abc=ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII) or die("Error"); 


// close the connection 
ftp_close($conn_id); 
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You two need to start using the formatting tags.
Post Reply