Tapatalk

How to save the active document to FTP via script

How to save the active document to FTP via script

3
NewbieNewbie
3

    May 08, 2014#1

    Hi,

    I have an active document created via script and i'm trying to save this file via script to FTP directory.
    I tried with the below example mentioned in the help topics but am not able to save it.

    if (UltraEdit.activeDocument.isHexModeOn()){

    //do these commands...

    } else {

    //do these commands...

    }

    Can you please give me a sample script to load an active file to ftp

    Thanks!

    115
    Power UserPower User
    115

      May 13, 2014#2

      It appears that you are quoting the help example from the script command isHexModeOn, not isFTP. The purpose of the command isFTP is to determine if the active file was entered into UltraEdit via the FTP/SFTP function. It doesn't actually do any FTP. That would be up to other script commands.

      In your question you refer to a file created by your script that you want to FTP save to a remote location. After setting your file as the active file when you check your file isFTP will return false. We know that since you just created the file, so it could not have been imported via FTP. So the ifFTP command is not really necessary in this case. All you really need is the script command to save via FTP.

      Since you want to save a file, you need to see what UltraEdit script commands can save files - and they are save and saveAs.

      UltraEdit.saveAs ("FTP::myserver.com\\/home/homedir/files/newfilename.ext")

      most of the line above are placeholder values that you would replace with your real paths and filenames.

      I haven't used a scrip to save via FTP so there may be a lot more you need to do with the command to make it work. Maybe someone else here has done it before.

      Mofi is the script expert so maybe he can provide more insight.

      6,685587
      Grand MasterGrand Master
      6,685587

        May 14, 2014#3

        MickRC3 wrote:Mofi is the script expert so maybe he can provide more insight.
        But not on questions related to FTP as I have never really used myself the FTP feature of UltraEdit/UEStudio. It should be clear that saving a file via FTP upload works only with an appropriate FTP account configured. Somebody else must help on this question.
        Best regards from an UC/UE/UES for Windows user from Austria

        115
        Power UserPower User
        115

          May 15, 2014#4

          Okay so I got it to work:

          create a script function like so:

          // Version = 1.00
          // ----------------------------------------------------------------------------
          // doFTPsave.js
          // This script saves the active file via FTP
          // ----------------------------------------------------------------------------

          function doFTPsave() {

          UltraEdit.saveAs ("SFTP::accountname\\/path/filename")

          }
          doFTPsave();



          I used SFTP as it is our method of accessing our servers. If your account uses FTP, enter FTP instead.
          Now replace "accountname" with the name of one of your UltraEdit FTP account names (make sure there are no spaces in the name).
          Replace "path" with the desired path on the remote machine
          Replace "filename" with the desired name. You may be able to put a variable here but I didn't try it. It does not appear to accept the extension you enter but instead replaces it with .000

            May 16, 2014#5

            After a few more tests I found when you save the file it uses the name of the file with the extension .000 on it, even if that name is different from the name listed in the script. I used testfile.txt and in the script called it the same thing so I missed that while doing the first tests. Later I selected a different file (testnetwork.txt) but forgot to change the script before I ran it. On the destination server the file was written as testnetwork.000 not as testfile.000

            3
            NewbieNewbie
            3

              May 19, 2014#6

              UltraEdit.saveAs("FTP::accountname\\path/Students_01_"+myTime+"_"+nHour+nMinute+nSecond+"_P.DAT");

              I use this but what happens is the tab which holds this active file displays that it is actually being saved in the path but it doesn't. I've waited for more than 30 mins to see if it actually saves but it doesn't.

              I'm using UltraEdit version 18.20.0.1021.

              115
              Power UserPower User
              115

                May 19, 2014#7

                UltraEdit did not use the file name I provided. Instead it took the file name from the active file, stripped off the existing extension and used .000 as the extension. I did not try to put it in a different directory than my home directory.

                Did you make sure that you correctly configured the FTP account in UltraEdit? This command will only work with an account name created by the UltraEdit FTP Manager. In other words, if you are user Alpha on system A999, you do not put Alpha here as UltraEdit does not know anything about it. Using UltraEdit FTP Manager you create an account that logs onto system A999 with user id of Alpha. For the purposes of this test I created a new account in UltraEdit FTP Manager. I called this account testftp. Since my server requires secure FTP, I used SFTP instead of FTP. I provided my home path and a dummy filename. When I invoked the script it used the name of the active file and performed the FTP session, transferring the file to the remote server.

                If you just created your file, you may have to save it to a local disk first so it really has a name or it may end up getting saved as Edit1.000 if the FTP works at all.

                3
                NewbieNewbie
                3

                  May 20, 2014#8

                  Ya it saves as .000 with extension!, I have configured my account via account manager!
                  Whats happening is that it saves the file to home directory (default) rather to the path which is mentioned in the command and it happens this way..

                  UltraEdit.saveAs("FTP::accountname\\path/Students_01_"+myTime+"_"+nHour+nMinute+nSecond+"_P.DAT");

                  it saves first as edit.000 in the default path and then saves as "Students_01..." in my local and then the file is renamed to FTP::accountname. :|

                  Tried the same approach via macro! it doesn't work.

                  115
                  Power UserPower User
                  115

                    May 21, 2014#9

                    Well, I think that IDM needs to know that the file name and path in the script is not used, that the active file name is used, the default path is used, and that the extension is replaced with .000 as I doubt that should be the normal operation. You can report the possible error to them using the contact link on the forum main page. I can verify that the behavior exists in UltraEdit 17.30.0.1014 and you indicate that the same condition happens in version 18.20.0.1021

                    My IT department is supposed to be installing 21.10x in the next few days. In big companies it takes a while to get things done (I requested the upgrade back in November right after V 20 came out). A minor upgrade for my office's dozen machines has a low priority, especially when the older version still works. When it is installed I'll see if the possible incorrect behavior remains.