Is there any way to upload a file to the tftp server?

Version 1
    This document was generated from CDN thread

    Created by: Jeff Garner on 06-10-2009 05:34:55 PM
    Is there any way to programmatically upload a phone configuration file to the tftp server?
     
    I'd like to upload a 3rd party SIP phone configuration file.
     

    Subject: RE: Is there any way to upload a file to the tftp server?
    Replied by: Dan-Anders Hook on 29-11-2009 10:17:18 PM
    Hi,
     
    Old thread, but still unanswered so maybe the question remains. It is possible to upload files to the TFTP server. This is done by a HTTP POST.
    Here's an example that uses curl to upload a file to the root directory of the TFTP:
     
    First, create a cookie:
     
    curl -i -k -v -G -ccookie.txt "https://192.168.0.10/cmplatform/WEB-INF/pages/j_security_check?appNav=cmplatform&j_username=administrator&j_password=cisco"
     
    Second, upload the file "testfile" into the root dir. The @ is important. If you want to upload to a different directory just specify the directory name and it will be automatically created if if does'nt exist.

    curl -v -i  -bcookie.txt mailto:-Ffile=@testfile -Fdirectory= -k https://192.168.0.10/cmplatform/tftpFileUpload.do
    Kind regards,
     
    //Dan

    Subject: RE: Is there any way to upload a file to the tftp server?
    Replied by: Dennis Heim on 18-08-2011 09:14:21 PM
    I tried this with 8.5. However, it does not seem to work. The cookie file is generated, but the file is not uploaded.
     
    Hi,
     
    Old thread, but still unanswered so maybe the question remains. It is possible to upload files to the TFTP server. This is done by a HTTP POST.
    Here's an example that uses curl to upload a file to the root directory of the TFTP:
     
    First, create a cookie:
     
    curl -i -k -v -G -ccookie.txt "<a>https://192.168.0.10/cmplatform/WEB-INF/pages/j_security_check?appNav=cmplatform&j_username=administrator&j_password=cisco</a>]"
     
    Second, upload the file "testfile" into the root dir. The @ is important. If you want to upload to a different directory just specify the directory name and it will be automatically created if if does'nt exist.

    curl -v -i  -bcookie.txt <a>mailto:-Ffile=@testfile</a>] -Fdirectory= -k <a>https://192.168.0.10/cmplatform/tftpFileUpload.do</a>]
    Kind regards,
     
    //Dan


    Subject: RE: Is there any way to upload a file to the tftp server?
    Replied by: Jason Rohm on 01-09-2011 06:40:56 PM
    There are some typos and/or improperly embedded HTML in the sample code.
     
    I have it working with the following commands...
     

    curl -i -k -v -G -c cookie.txt 'https://10.1.1.1/cmplatform/WEB-INF/pages/j_security_check?appNav=cmplatform&j_username=admin&j_password=MyPassword'

    curl -v -i  -b cookie.txt -Ffile=@MyFileName -Fdirectory=. -k https://10.1.1.1/cmplatform/tftpFileUpload.do
     
    Also, note that you are logging into the platform interface, not the CUCM interface, so if you have different logins for the platform than CUCM (I do), you need to use the right one.
     
    Jason
     

    Subject: RE: Is there any way to upload a file to the tftp server?
    Replied by: Jason Rohm on 03-09-2011 04:09:17 PM
    I did a little more testing and found that the code I submitted is NOT working in 8.5 as expected.
     
    The sample code will work successfully to upload to publisher. However, when used to upload to a subscriber, behavior varies. I am testing code to automatically update ringtones. When I upload the 'Ringlist.xml' file, subscribers will return a '200 Ok' message, but silently discard the actual upload. When uploading my actual ringer file, the subscribers return a '302 Moved Temporarily' and redirect to the PUBLISHER's OS interface, also not accepting the upload.
     
    I will continue to test and update the thread.

    Subject: RE: Is there any way to upload a file to the tftp server?
    Replied by: Jason Rohm on 03-09-2011 09:27:58 PM
    I've done more extensive testing and have found the following behavior:
     
    The code provided works, but not consistently. It seems that occasionally the web server will silently (more or less) reject the upload while sending a "200 Ok" message back.
     
    I am able to test for a real success or a fake success by parsing the returned HTML page for the embedded status message. A failed transfer will produce a "Status: Ready" message while a successful transfer will produce a "Status: File uploaded successfully" message. Also, a successful transfer will product an HTML form with the uploaded file populated in the input field, while a failed upload will not.
     
    It is an ugly hack, but it works around the problem and produces successful uploads consistently.
     
    I'm still a little miffed that there isn't a more elegant AXL mechanism for this.
     
    Sample working PHP code for uploading a ringlist to each server:
     
    <?php
    $s_CUCM_OS_UID='adminUID';
    $s_CUCM_OS_PWD='adminPwd';
    $a_CUCM_Servers=array('10.1.1.1', '10.1.1.2');
    foreach($a_CUCM_Servers as $s_CUCM_Server) {
      $s_shell_exec = "curl -i -k -v -G -c cookie.txt 'https://" . $s_CUCM_Server . "/cmplatform/WEB-INF/pages/j_security_check?appNav=cmplatform&j_username=" . $s_CUCM_OS_UID . "&j_password=" . $s_CUCM_OS_PWD . "'";
      echo shell_exec($s_shell_exec); 
      $s_shell_exec = "curl -v -i -b cookie.txt -F file=@Ringlist.xml -F directory= -k 'https://" . $s_CUCM_Server . "/cmplatform/tftpFileUpload.do' 2> /dev/null";
    $i_Runs = 0;
    $i_upload_error = 0;
    do {
      $i_Runs++;
      $s_output =  shell_exec($s_shell_exec);
      $i_upload_error = preg_match('/Status:\sFile/', $s_output, $s_match);
    } while((!($i_upload_error)) && $i_Runs < 10);
    ?>