ftp and PHP

I'm having trouble getting the following code to work:

<?php
  // RAY_temp_hrolsons.php
error_reporting(E_ALL);

$offs_x=0;
$offs_y=0;

print_r($_SERVER['argv']);

ini_set('memory_limit', '5000M');

$original=$_SERVER["argv"][1];

$file=$original;

// open some file for reading
$fp = fopen($file, 'r');

$ftp_server='ftp.photobox.com';
$ftp_user_name='myusername@gmail.com';
$ftp_user_pass='mypassword;

$remote_file = $file;

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

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);

?>

Open in new window


It runs through, but always ends in 'There was a problem while uploading...'

Any ideas?
hrolsonsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Maybe consider testing the return values from the various PHP functions.  These functions have return values.  Please print them out using var_dump() and post the information here.

fopen
ftp_connect
ftp_login
ftp_put
ftp_close
0
hrolsonsAuthor Commented:
Sorry Ray, I'm not quite following.  I tried var_dump(fp); resource(5) of type (stream)
0
Ray PaseurCommented:
That's the first of five.  Please use var_dump() to print the other four values.  Until we see what is coming back from the PHP functions we will just be guessing.
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

hrolsonsAuthor Commented:
So, here are 4:

fopen=resource(5) of type *stream)
ftp_connect=resource(6) of type (FTP Buffer)
ftp_login=bool(true)
ftp_close=bool(true)

I'm not sure how to get it from ftp_put.  I tried:

$put_result=ftp_put($conn_id, $remote_file, $file, FTP_ASCII;
var_dump($put_result);

But that didn't work.
0
Ray PaseurCommented:
I'm fairly sure "didn't work" is not an error message.  What is the code you used and what is the output from that code?
0
hrolsonsAuthor Commented:
Sorry, I was missing a parwnthesis.  ftp_put returned bool(false)  Here is a screenshot:

screenshot
0
Dave BaldwinFixer of ProblemsCommented:
Sending a 'jpg' in ASCII mode will cause errors in the file.  Use  FTP_BINARY for images.

Adding 'ftp_pasv' after the connection made it work for me on this Windows box.  I did reduce the memory_limit to 500M but I don't thing that had anything to do with it.
<?php
  // RAY_temp_hrolsons.php
error_reporting(E_ALL);

$offs_x=0;
$offs_y=0;

print_r($_SERVER['argv']);

ini_set('memory_limit', '5000M');

$original=$_SERVER["argv"][1];

$file=$original;

// open some file for reading
$fp = fopen($file, 'r');

$ftp_server='ftp.photobox.com';
$ftp_user_name='myusername@gmail.com';
$ftp_user_pass='mypassword;

$remote_file = $file;

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

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// turn passive mode on <<<<<<<<<<<<<<<<<<
ftp_pasv($conn_id, true);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);

?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hrolsonsAuthor Commented:
Thank you so much!!!
0
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.