473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

File Upload using ftp commands

Because of limitations of my provider, I am forced to use the ftp
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).

I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.

David

Expand|Select|Wrap|Line Numbers
  1. ---------------------
  2. <?php
  3. $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
  4. echo "<pre>" . print_r($tmp) . "</pre>";
  5.  
  6. $upload_form_file = $tmp['name']; // have tried using the tmp_name
  7. element combined with ftp_fput
  8. $dest_file = "bob.gif"; // just a name to try
  9.  
  10. // set up a connection or die
  11. $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
  12. $ftp_server"); // works
  13.  
  14. // try to login
  15. if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  16. echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
  17. } else {
  18. echo "Couldn't connect as $ftp_user\n";
  19. }
  20.  
  21. echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
  22. this gives the root
  23.  
  24. if (ftp_chdir($conn_id, $base_path)) {
  25. echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
  26. // this prints /the/path/to/docs
  27. } else {
  28. echo "Couldn't change directory\n";
  29. }
  30.  
  31. echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
  32. </p>\n"; // files are listed
  33.  
  34. if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
  35. echo "successfully uploaded";
  36. } else {
  37. echo "There was a problem while uploading $file\n"; // this always
  38. triggers
  39. }
  40.  
  41. // close the connection
  42. ftp_close($conn_id);
  43.  
  44. ?>
  45.  
Jul 17 '05 #1
3 2262
Dude:

Here I am replying to myself on the list so that others won't suffer as
I have. I finally figured out that ftp_put and ftp_fput are running *on
the server* and so don't know anything about the client's file system.
They are putting files from the php server onto some other remote
server. Therefore, the only file they are going to know about is the
temp file that php creates on the fly. Once I changed my code to use the
php tmp file, the upload worked smoothly.

HTH,
David

David wrote:
Because of limitations of my provider, I am forced to use the ftp
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).

I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.

David

Expand|Select|Wrap|Line Numbers
  1.  ---------------------
  2.  <?php
  3.  $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
  4.  echo "<pre>" . print_r($tmp) . "</pre>";
  5.  $upload_form_file = $tmp['name']; // have tried using the tmp_name
  6.  element combined with ftp_fput
  7.  $dest_file = "bob.gif"; // just a name to try
  8.  // set up a connection or die
  9.  $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
  10.  $ftp_server"); // works
  11.  // try to login
  12.  if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  13.     echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
  14.  } else {
  15.     echo "Couldn't connect as $ftp_user\n";
  16.  }
  17.  echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
  18.  this gives the root
  19.  if (ftp_chdir($conn_id, $base_path)) {
  20.     echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
  21.  // this prints /the/path/to/docs
  22.  } else {
  23.     echo "Couldn't change directory\n";
  24.  }
  25.  echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
  26.  </p>\n"; // files are listed
  27.  if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
  28.   echo "successfully uploaded";
  29.  } else {
  30.   echo "There was a problem while uploading $file\n"; // this always
  31.  triggers
  32.  }
  33.  // close the connection
  34.  ftp_close($conn_id);
  35.  ?>
  36.  

Jul 17 '05 #2


David wrote:

Because of limitations of my provider, I am forced to use the ftp
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).

I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.

David

Expand|Select|Wrap|Line Numbers
  1.  ---------------------
  2.  <?php
  3.  $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
  4.  echo "<pre>" . print_r($tmp) . "</pre>";
  5.  $upload_form_file = $tmp['name']; // have tried using the tmp_name
  6.  element combined with ftp_fput
  7.  $dest_file = "bob.gif"; // just a name to try
  8.  // set up a connection or die
  9.  $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
  10.  $ftp_server"); // works
  11.  // try to login
  12.  if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  13.      echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
  14.  } else {
  15.      echo "Couldn't connect as $ftp_user\n";
  16.  }
  17.  echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
  18.  this gives the root
  19.  if (ftp_chdir($conn_id, $base_path)) {
  20.      echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
  21.  // this prints /the/path/to/docs
  22.  } else {
  23.      echo "Couldn't change directory\n";
  24.  }
  25.  echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
  26.  </p>\n"; // files are listed
  27.  if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
  28.    echo "successfully uploaded";
  29.  } else {
  30.    echo "There was a problem while uploading $file\n"; // this always
  31.  triggers
  32.  }
  33.  // close the connection
  34.  ftp_close($conn_id);
  35.  ?>
  36.  


You will definitely have to use tmp_name.

Are you sure the user you're connecting with has the ability to upload files to
the specified directory? If you're not absolutely sure, try it manually with
your ftp program.

Also, you might want to put error_reporting(E_ALL); at the top of your script.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3


David wrote:

Because of limitations of my provider, I am forced to use the ftp
functions to upload files to my server (the permissions on the server
will not allow me to load files via php).

I have successfully ported the sample code from php.net to do everything
BUT upload the file. I can connect. I can log in. I can change
directories. But the file never uploads. As I note in the code, I have
tried using ftp_put with the local filename, and I have tried using
ftp_fput with the file in /tmp/php with no luck. Suggestions are welcome.

David

Expand|Select|Wrap|Line Numbers
  1.  ---------------------
  2.  <?php
  3.  $tmp = $_FILES['loadfile']; // passed in correctly as shown on next line
  4.  echo "<pre>" . print_r($tmp) . "</pre>";
  5.  $upload_form_file = $tmp['name']; // have tried using the tmp_name
  6.  element combined with ftp_fput
  7.  $dest_file = "bob.gif"; // just a name to try
  8.  // set up a connection or die
  9.  $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to
  10.  $ftp_server"); // works
  11.  // try to login
  12.  if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
  13.      echo "<p>Connected as $ftp_user@$ftp_server</p>\n"; // this is printed
  14.  } else {
  15.      echo "Couldn't connect as $ftp_user\n";
  16.  }
  17.  echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n"; //
  18.  this gives the root
  19.  if (ftp_chdir($conn_id, $base_path)) {
  20.      echo "<p>Current directory is now: " . ftp_pwd($conn_id) . "</p>\n";
  21.  // this prints /the/path/to/docs
  22.  } else {
  23.      echo "Couldn't change directory\n";
  24.  }
  25.  echo "<p>upload_form_file: $upload_form_file <br>\ndest_file: $dest_file
  26.  </p>\n"; // files are listed
  27.  if (ftp_put($conn_id, $dest_file, $upload_form_file, FTP_BINARY)) {
  28.    echo "successfully uploaded";
  29.  } else {
  30.    echo "There was a problem while uploading $file\n"; // this always
  31.  triggers
  32.  }
  33.  // close the connection
  34.  ftp_close($conn_id);
  35.  ?>
  36.  


You will definitely have to use tmp_name.

Are you sure the user you're connecting with has the ability to upload files to
the specified directory? If you're not absolutely sure, try it manually with
your ftp program.

Also, you might want to put error_reporting(E_ALL); at the top of your script.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim218 | last post by:
Hi Everyone This is my first day with PHP and, not surprisingly, I've run into a problem :-) I want to allow file uploads to the server without exposing the non-technical end-users to FTP...
7
by: OneSolution | last post by:
Hi All, Here's one thing that I don't know much about - file uploading. As part of my project, I will have to build a file manager of sorts - perhaps a document manager. Anyhow, this involves...
18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
3
by: Nexus | last post by:
I have created a program in Visual Basic that creates CSV file on the PC. However I need to do an upload of these files into DB2 tables (from time to time) I'm currently using ADO to create a...
4
by: Ashok | last post by:
Dear Friends, How to download a file from server to client local pc without user intervention ie without the save as popup window. Can you give me step by step. Thanks
2
by: fReDiNi | last post by:
Hi, I have being trying fo find the best solution for this problem for 2 days now and I am not able to find a solution.I need help. I explain the problem: A customer needs a system so that...
3
by: Bonzol | last post by:
Vb.net 2003, Web application Hey all! Just a quick question. I have a site which allows users the ability to upload files by the HTML brows button control. My question is if a user submits...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.