0

Upload local files to tropo acount through Tropo FTP

Hi Tropo

Is it possible to upload files from my server to my account using html and PHP? I am using a post method in my HTML but it appears to fail each time "HTTP Error 405.0 - Method Not Allowed".

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
  <body>
    <form enctype="multipart/form-data" action="" method="POST">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
      <input name="uploadedfile" type="file" />
      <input type="submit" value="Upload File" />
    </form>
  </body>
</html>

<?php
$ftp_server = "ftp.tropo.com";
$ftp_user_name = "XXX";
$ftp_user_pass = "XXX";
$destination_file = "XXX";
$source_file = $_FILES['file']['tmp_name'];

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

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

// check connection
if ((!$conn_id) || (!$login_result)) {
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name";
    exit;
} else {
    echo "Connected to $ftp_server, for user $ftp_user_name";
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// close the FTP stream
ftp_close($conn_id);
?>

Thank you,

Joe

1 comment

Please sign in to leave a comment.