Solved

FTP upload error

Posted on 2007-04-10
9
527 Views
Last Modified: 2013-12-13
I am trying to make ftp uploadform.  We have runninf ftpserver which located different server than php. There is a directory named 'incoming'. Those upload files have to go on that directory.
Here is my error message:
Connected to ftp.studio.fi, for user asiakas
Warning: ftp_put() [function.ftp-put]: Access denied. in c:\inetpub\wwwroot\upload.php on line 31
FTP upload of login_05.jpg has failed!

And here is code:

<?php
if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != ""){
   
    $local_file = $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded

    $destination_file = "/".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)

    // Global Connection Settings
    $ftp_server = "ftp.studio.fi";      // FTP Server Address (exlucde ftp://)
    $ftp_user_name = "asiakas";     // FTP Server Username
    $ftp_user_pass = "studio";      // Password
    // Connect to FTP Server
    $conn_id = ftp_connect($ftp_server);
    // Login to FTP Server
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
             // turn passive mode on
    ftp_pasv($conn_id, true);
    // Verify Log In Status
    if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed! <br />";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name <br />";
    }
    $upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY);  // Upload the File
    // Verify Upload Status
    if (!$upload) {
        echo "<h2>FTP upload of ".$_FILES['txt_file']['name']." has failed!</h2><br /><br />";
    } else {
        echo "Success!<br />" . $_FILES['txt_file']['name'] . " has been uploaded to " . $ftp_server . $destination_file . "!<br /><br />";
    }
    ftp_close($conn_id); // Close the FTP Connection
}
?>
<html>
    <head>
        <script type="text/javascript">
            window.onload = function() {
                document.getElementById("progress").style.visibility = "hidden";
                document.getElementById("prog_text").style.visibility = "hidden";
            }
            function dispProgress() {
                document.getElementById("progress").style.visibility = "visible";
                document.getElementById("prog_text").style.visibility = "visible";
            }
        </script>
    </head>
    <body>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
            Valitse tiedosto: <input name="txt_file" type="file" size="35" />
            <input type="submit" name="start_upload" value="Upload File" onClick="dispProgress()" />
        </form>

Here is info about php.ini file
- FTP support  enabled
- upload_tmp_dir C:\PHP\uploadtemp  
0
Comment
Question by:tikkanen
  • 3
  • 3
  • 3
9 Comments
 
LVL 19

Expert Comment

by:v2Media
ID: 18881630
FTP on windows via php is a bit fiddly. First, you need a fully functional FTP system. Once FTP is working correctly, then you know PHP or permissions are to blame. In you case, I'd say permissions.

Check out this article on setting up FTP on win2k3; much of it will apply to an XP box as well...

http://www.windowsnetworking.com/articles_tutorials/Creating-Configuring-FTP.html
0
 
LVL 48

Expert Comment

by:hernst42
ID: 18881638
Shouldn' this line:
$destination_file = "/".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)
be more like
$destination_file = "./".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)
so it matches the comment?
0
 

Author Comment

by:tikkanen
ID: 18883657
Correction, we have ftp server (war daemon manager) same server as php. Our customer can upload files with ftp-program. When they tranfers files they have to be  on passive mode or 'passive transfer'.
All files have to go ingoming directory.
ftp://ftp.printstudio.fi/

I change lines "./" and i get next error message:

Connected to ftp.printstudio.fi, for user asiakas
Warning: ftp_put() [function.ftp-put]: Access denied. in c:\inetpub\wwwroot\upload.php on line 32
Line 32 is this:     $upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY);  // Upload the File
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 19

Expert Comment

by:v2Media
ID: 18886446
IUSR_COMPUTERNAME needs to have write permissions to the directory.
0
 
LVL 19

Accepted Solution

by:
v2Media earned 250 total points
ID: 18886465
I strongly suggest reading the article I posted above to ensure your ftp server is configured with some kind of security, otherwise you're opening yourself up to warez crews discovering free ftp space to mirror their files.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 18887810
Maybe the settings of your ftp-server does not allow a user from localhost to upload files, even if he is allowed to upload from an external ip? The problem is the configuration of your ftp-server. Check the logs there
0
 

Author Comment

by:tikkanen
ID: 18888106
Is it more secure and clear to make an upload form where user can upload stuff on php server. Not ftp server? Any suuggestion?
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 250 total points
ID: 18888131
upload via form and php-verification is more secure than giving anyone write access to a ftp-server. Ifyou store the uploaded files in a ftp-server or on the webserver does not really matter.
0
 

Author Comment

by:tikkanen
ID: 18888606
Ok, I will try that. Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question