Solved

FTP upload error

Posted on 2007-04-10
9
526 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP & MySQL - Rounding Results from a Select Query 3 25
Insert values are dynamic 11 41
Google Maps API and PHP 25 30
comma true 6 33
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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