25 Replies Latest reply on Nov 4, 2013 11:19 AM by ThePromenader

    Get file from ftp

    maphiom Level 1

      Hi all,

       

      I looked on the forum for answers on that topic but didn't really find anything simple.

       

      I would like my Photoshop javascript to retrieve a specific image file from a ftp server before doing its thing inside Photoshop.

      I tried putting the ftp address along with login and password the same way I would specify a local path, but this doesn't seem to work (this might be an obvious mistake, my javascript knowledge being somewhat limited). Is there another way?

       

      Thanks,

       

      John

        • 1. Re: Get file from ftp
          Michael L Hale Level 5

          I am not sure how you get a file from an FTP server but the script below shows how to get one using HTTP. Note it is old and the URL in the sample doesn't work for me. If I change the URL to an address I know is good it works.

          // openImageFromWeb.jsx 
          // Copyright 2006-2009 
          // Written by Jeffrey Tranberry 
          // Photoshop for Geeks Version 3.0 
          
          /* 
          Description: 
          This sample script shows how to download images from a web server using the Socket object. 
          */ 
          
          // Note: Socket.read() parameter & behavior 
          // Socket.read() will read or time out. It may not read all data from server. 
          // Socket.read(999999) will read 999999 bytes, or timeout, or socket will be 
          // closed by the server. 
          
          // enable double clicking from the 
          // Macintosh Finder or the Windows Explorer 
          #target photoshop 
          
          // Make Photoshop the frontmost application 
          app.bringToFront(); 
          
          ///////////////////////// 
          // SETUP 
          ///////////////////////// 
          
          var socket = new Socket; 
          var html = ""; 
          var domain = "www.jkost.com" // the domain for the file we want 
          var sImg = "/images/JKOST_2008_03600.jpg"; // the rest of the url for the file we want ### may no longer be a valid url
          var port = ":80"; // the port for the file we want 
          
          ///////////////////////// 
          // MAIN 
          ///////////////////////// 
          
          
          var f = File("~/socket_sample_" + sImg.substr(sImg.length-4)); // 4 = .gif or .jpg 
           f.encoding  = "binary";  // set binary mode 
           f.open("w"); 
          
          if (socket.open(domain + port, "binary")){ 
           // alert("GET " + sImg +" HTTP/1.0\n\n"); 
           socket.write("GET " + sImg +" HTTP/1.0\n\n"); // get the file 
           var binary = socket.read(9999999); 
           binary = removeHeaders(binary); 
           f.write(binary); 
           socket.close(); 
           } 
          
           f.close(); 
           app.open(f);// Open files in Photoshop 
           f.remove();  // Remove temporary downloaded files 
          
          ///////////////////////// 
          // FUNCTIONS 
          ///////////////////////// 
          
          // Remove header lines from HTTP response 
          function removeHeaders(binary) 
          { 
           var bContinue = true ; // flag for finding end of header 
           var line = ""; 
           var nFirst = 0; 
           var count  = 0; 
           while (bContinue) { 
           line = getLine(binary) ; // each header line 
           bContinue = line.length >= 2 ;  // blank header == end of header 
           nFirst = line.length + 1 ; 
           binary = binary.substr(nFirst) ; 
           } 
           return binary; 
          } 
          
          
          // Get a response line from the HTML 
          function getLine(html) 
          { 
           var line = "" ; 
           for (var i = 0; html.charCodeAt(i) != 10; i++){ // finding line end 
           line += html[i] ; 
           } 
           return line ; 
          }
          
          • 2. Re: Get file from ftp
            maphiom Level 1

            Hi,

             

            thanks for the tip Michael. I tried using this script, changing the values at the beginning to an image on an http website to try it out, but when I run it I get a "Cannot open the file because the open options are incorrect" error. Do you know where that could come from?

             

            Thanks,

            John

            • 3. Re: Get file from ftp
              Michael L Hale Level 5

              At a guess I would say that whatever you used is still not a valid URL. The script seems to assume the file will be downloaded and tries to open it. The original 'www.jkost.com'URL now returns a text file( html ) which Photoshop tries to open and of course can't.

               

              So I would step through the script in ESTK and check the var 'binary' right before the line  f.write(binary); If the console looks like html then it not a valid image URL.

               

              One other cause of that error may be that the script can not connect to the Internet. You may have to check your firewall settings, etc.

              socket.open is in an if block but that block does not include the open statement so even if the socket can't be open it still tries to open a file that wasn't even downloaded. You could move the closing bracket of the if statement to after the line  f.remove();. That is what I would have done but I wanted to post the script as written.

              • 4. Re: Get file from ftp
                maphiom Level 1

                Hmmm this is strange. As you thought the address turns up a html file, but

                I've tried with several urls I know exist, each time getting the same

                result.

                I tried disabling my firewall but it didn't solve the problem.

                 

                I also moved the bracket as you suggested, but the script still tries to

                open the file, getting the same error.

                 

                Is it working for you?

                • 5. Re: Get file from ftp
                  Michael L Hale Level 5

                  Yes, it works for me if I change the URL. Here is what I used to test.

                   

                   

                  var domain = 'www.edubose.com';
                  var sImg = '/client/images/image001.jpg';
                  
                  • 6. Re: Get file from ftp
                    maphiom Level 1

                    Indeed! It didn't work with any of the websites I tried but it does work

                    with this one. I wonder why.

                     

                    I tried writing my ftp server's address instead but I guess the script's

                    still looking for an http server.

                    • 7. Re: Get file from ftp
                      Michael L Hale Level 5

                      For what it is worth, I can not get it to work with any of my sites hosted by GoDaddy on a shared server. I get an html doc returned that says file not found even though I know the file is on the server. So it may be the type of server or their settings matters.

                      • 9. Re: Get file from ftp
                        maphiom Level 1

                        Thanks ! That seems to be exactly it.

                         

                        Although... I have a very rough understanding of how this script works, but I'm having trouble integrating it into my existing script. I'm not sure at which point in the script I should declare the variables hostS, port, unameS, upassS, localPath, remotePathS.

                         

                        Then should I add lines to call the functions this.open(), this.get(), this.close() ?

                         

                        Sorry if those seem like very basic questions, but I'm learning!

                         

                        Thanks

                        John

                        • 10. Re: Get file from ftp
                          jugenjury Level 2

                          OK. To use this you have to include it in your script file. This should go near the beginning of your script.

                          #include "FTPConnection.jsx" (Or whatever the filename is that you saved it as.)

                          Then declare your ftp connection object

                           

                          ftp=new FTPConnection();

                          Then use it.

                           

                          ftp.open("ftp://ftp.yourhost.com","port#","username","password");

                          ftp.get("LocalFile","RemoteFile");

                          I haven't tested this, but it should work. You may want to already set a pointer to your local file so you can then access it once this is done.

                           

                           

                          var ftpFile=new File("PathToFile\Filename.jpg");

                          Then for your get line:

                           

                          ftp.get(ftpFile,"RemoteFile");

                          Then once the download finishes, you close the ftp connection and open your file:

                           

                          ftp.close();

                          ftpFile.open();

                           

                          I hope this helps.

                          • 11. Re: Get file from ftp
                            JJMack Most Valuable Participant

                            jugenjury wrote:

                             

                            OK. To use this you have to include it in your script file. This should go near the beginning of your script.

                            #include "FTPConnection.jsx" (Or whatever the filename is that you saved it as.)

                            Then declare your ftp connection object

                             

                            ftp=new FTPConnection();

                            Then use it.

                             

                            ftp.open("ftp://ftp.yourhost.com","port#","username","password");

                            ftp.get("LocalFile","RemoteFile");

                            I haven't tested this, but it should work. You may want to already set a pointer to your local file so you can then access it once this is done.

                             

                             

                            var ftpFile=new File("PathToFile\Filename.jpg");

                            Then for your get line:

                             

                            ftp.get(ftpFile,"RemoteFile");

                            Then once the download finishes, you close the ftp connection and open your file:

                             

                            ftp.close();

                            ftpFile.open();

                             

                            I hope this helps.

                            I did a test and look a wee bit at at the FTPconnection script.  It states its not well tested and when I tried it I did not change the transfet mode to binary all I tried to do was to get my web site index.html into c:\test.html.   The FTP.get only retrieved a small portion of the beginnong of the index.html file. Here is what my test script looked like.  I made a test for open working if it fails and you do a FTP.get  Photoshop Loops using 90%CPU.

                             

                            //OK. To use this you have to include it in your script file. This should go near the beginning of your script.

                            #include "FTPConnection.jsx"

                            //Then declare your ftp connection object

                            ftp=new FTPConnection();

                            //Then use it.

                            if (ftp.open("sitename.net","21","userid","password") ) {

                                      var ftpFile=new File("C:/test.html");

                                      //Then for your get line:

                                      alert("Get " + ftpFile + " From index.html" );

                                      ftp.get(ftpFile,"index.html");

                                      //Then once the download finishes, you close the ftp connection and open your file:

                                      alert("Close");

                                      ftp.close();

                                      //alert("Open Downloaded File");

                                      //ftpFile.open();

                                       }

                                      else { alert("FTP Open Connection Failed");}

                             

                             

                            Took a little closer look at FTPconnection secript I saw some loop commented out in routines like get and put un-commenting the loop int the get allowed my test script to get the whole index.html.   The script seems to be by Author:  Peter Torpey  www.petertorpey.com Version:  1.1    01-21-24-05 has know issues and was NOT tested well and in the past 6 years was not updated to inclued the authors intended features in other words the script died.

                             

                            Message was edited by: JJMack

                            • 12. Re: Get file from ftp
                              JJMack Most Valuable Participant

                              The get that worked for me looks like this. However  I'm only looking at FTPconnection.jsx for I alway wanted a way to upload images from photoshop.  I want to look at the put ability but from reading the comments in that script it looks like the folder involved in get and put must exists seems there is no make directory function too bad. I also see that if I set verbose to 1 the loging in FTPconnection.jsx  does not work.

                               

                              //OK. To use this you have to include it in your script file. This should go near the beginning of your script.

                              #include "FTPConnection.jsx"

                               

                              //Then declare your ftp connection object

                              ftp=new FTPConnection("verbose");

                               

                              //Then use it.

                              //ftp.open("yourhost.com","port#","username","password");

                              if (ftp.open("yourhost.com","21","username","password") ) {

                                        //ftp.get("LocalFile","RemoteFile");

                               

                                        var RemoteFile= "Grandpa.jpg";

                                        ftp.setEncodingBinary();

                               

                                        var ftpFile=new File("D:/FTP/download/" + RemoteFile);

                                        //alert("ftpFile = " + ftpFile);

                               

                                        alert("Get " + ftpFile + " From " + RemoteFile );

                                        if (ftp.get(ftpFile,RemoteFile) ) {

                                                  //Then once the download finishes, you close the ftp connection and open your file:

                                                  //alert("Close");

                                                  ftp.close();

                                                  alert("Open Downloaded File");

                                                  open(File(ftpFile));

                                                  } else { alert("FTP Get Failed " + ftp.error);}

                                        } else { alert("FTP Open Connection Failed " + ftp.error );}

                               

                              • 13. Re: Get file from ftp
                                xbytor2 Level 4

                                One other way to solve this problem is to use Bridge. It has a builtin FTPConnnection class with nearly all the features you might need. I implemented a script for PS (xtools/xlib/FTP.jsx) that makes calls to Bridge to do the actual FTP bits. I needed to upload entire directory trees at a time and this was (at the time) the simplest way to do it. If I were to do this again today, I would write a perl script that calls ftp/sftp and call that via app.system().

                                • 14. Re: Get file from ftp
                                  JJMack Most Valuable Participant

                                  xbytor2 wrote:

                                  I needed to upload entire directory trees at a time and this was (at the time) the simplest way to do it.

                                  Yes that is what I wanted to do also.  However when I saw how long it took the Bridge to upload a Web Gallery. I desided not to do use FTP within an Adobe products.  I just build the tree wiith a Photoshop script and test the tree in a Web browser that is started from the Photoshop script. If the test is good I just FTP upload the tree with IE using a drag and drop.  So I can use Photoshop at the same time the tree is being FTPed to my Web Server.

                                  • 15. Re: Get file from ftp
                                    JJMack Most Valuable Participant

                                    //OK. To use this you have to include it in your script file. This should go near the beginning of your script.

                                    #include "FTPConnection.jsx"

                                     

                                    var downloadTo="D:/FTP/download/";

                                    var ftpPort="21";

                                    var username="anonymous";

                                    var password="password";

                                     

                                    //avoide undefined

                                    var domain="";

                                    var imagePath="";

                                    var Name="";

                                    var url="";

                                     

                                    var url = prompt("Enter the image's full URL http://domain/full image path",url);   // prompt for domain name

                                    if (url != ""){

                                              if ( (url.indexOf("http://") != -1)  || (url.indexOf("HTTP://") != -1)  ) {

                                                        domainPathLength = url.length - "http://".length;

                                                        domainPath = url.substr(7, domainPathLength);

                                                        pathOffset = domainPath.indexOf("/");

                                                        domain = domainPath.substr(0, pathOffset);

                                                        sImg = domainPath.substr(pathOffset, domainPath.length - pathOffset );

                                                        // Isolate Image name

                                                        var Name =  sImg

                                                        var imagePath = "";

                                                        while (Name.indexOf("/") != -1 ) {                                        // Strip Path

                                                                  imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);

                                                                  Name = Name.substr(Name.indexOf("/") + 1 ,);

                                                                  }

                                                        }

                                              } else { alert("No URL Provided");}

                                     

                                    if  ( (domain != "") && (imagePath != "") && (Name != "") ) {

                                              try {

                                                        //Then declare your ftp connection object

                                                        ftp=new FTPConnection();

                                                        //Then use it.

                                                        //ftp.open(domain, ftpPort, username ,password);

                                                        if (ftp.open(domain, ftpPort, username ,password) ) {

                                     

                                                                  var RemoteFile= imagePath + Name;

                                                                  ftp.setEncodingBinary();

                                     

                                                                  var ftpFile=new File(downloadTo + Name);

                                     

                                                                  if (ftp.get(ftpFile,RemoteFile) ) {

                                     

                                                                            //Then once the download finishes, you close the ftp connection and open your file:

                                                                            ftp.close();

                                     

                                                                            open(File(ftpFile));

                                                                            } else { alert("FTP Get " + ftpFile + " From " + RemoteFile  + " Failed " + ftp.error );}

                                                                   } else { alert("FTP Open Connection Failed " + ftp.error );}

                                                        }

                                                        // display error message if something goes wrong

                                                        catch(e) {

                                                                  if (e.line != undefined) { alert(e + ': on line ' + e.line, 'Script Error', true); }

                                                                  else { alert(e, 'Script Error', true); }

                                                                  }

                                              } else { if (url != "") { alert("invalid URL: " + url);} }

                                     

                                    • 16. Re: Get file from ftp
                                      maphiom Level 1

                                      No matter what I do the scripts loop endlessly.

                                      What is the url part about in your last script, JJMack, since we're talking ftp?

                                      • 17. Re: Get file from ftp
                                        JJMack Most Valuable Participant

                                        I found that Jeff script seem to time out on large files using http port 80 file transfer incomplete. I had url code like the in his script so I could  copy an image URL from my browser and past it into the prompt field.  What is good about http port 80 is the domain need not be set up for FTP and you do not need to login.  Using FTP port  21 the domain must enable FTP and you may need to login with a real userid. I put the URL code in there so I could use the old code I had with some minor changes  so I can still paste the URL into the prompt field.  In the script the http and :// is striped out and  what remains is parse to get the domain, the server file path and the file name.

                                         

                                        I have had Photoshop Loop at times also.  You may want to put some alert messages in before the script uses the FTPconnection functions so you kinow what causes the loop.  When it loop on me I can often logoff and back on and do the same test and all works? The loop seems to be in the get function.  Prehaps in the loop I uncommented in FTPconnection.jsx perhats and alert in there may show its in there. When the loop is commented out the whole file is not transfered.

                                        • 18. Re: Get file from ftp
                                          maphiom Level 1

                                          I see! Thanks for explaining

                                           

                                          I might be mistaken but the loop seems to be this part of the FTPConnection.jsx

                                           



                                          // bypass any marks (and empty lines)


                                          do {



                                          replyS = controlChannel.read();



                                          if (_FTPC_DO_LOG) logFile.write("+" + replyS);



                                          code = replyS.match(/^(\d{3})\s/m);
                                          • 19. Re: Get file from ftp
                                            JJMack Most Valuable Participant

                                            FTPconnection.jsx is very old not well tested has limitations with sections commented out. Others have reported problems with it you can find on the on the web. I don't plain on use it myself.  If you want to use FTP within Photoshop I would think X's code would be better.  He was able to upload whole trees using calls to the Bridge to use its built in FTP connection feature,  Even he would do it differently these days. Seems he has perl on his system. I suspect he may be using a mac its OS is a unix type system and most likely has perl installed by default.  There are perl inplmentations for windows also. Transferinf Tree takes a long time. I'm retired can't type so I don't like to mess with code that much.  Just use it to keep my mind functioning somewhat.  I never even stuided javascript or read a manual just hack a bit.  When my head starts to ack I move on for I'm not getting paid to rack my mind any more.

                                             

                                            For simple downloads Jeff's script wotks quite well and places the image into your current document or a new document  if an active document does not exist. I've used it to even download RAW file found on the web.  I think the code will also change the active document size if the image being placed is larger the the active document.  Some script listener code is used to do the place. Here is my modfied code.

                                            // OpenImageFromWeb.jsx

                                            // Copyright 2006-2009

                                            // Written by Jeffrey Tranberry

                                            // Photoshop for Geeks Version 3.0

                                            // modified by MLH

                                            // modified by JJMACK 2010

                                            /*

                                            <javascriptresource>

                                            <about>$$$/JavaScripts/OpenImageFromWeb/About=JJMack's OpenImageFromWeb.^r^rCopyright 2010 Mouseprints.^r^rJJMack's Script.^rOpen Image

                                             

                                             

                                            From Web as a smart object layer!</about>

                                            <category>JJMack's Script</category>

                                            </javascriptresource>

                                            */

                                             

                                             

                                            /*

                                            Description:

                                            This sample script shows how to download images from a web server using the

                                            Socket object.

                                            */

                                             

                                            // Note: Socket.read() parameter & behavior

                                            // Socket.read() will read or time out. It may not read all data fromserver. <---------------

                                            // Socket.read(999999) will read 999999 bytes, or timeout, or socket will be

                                            // closed by the server.

                                             

                                            // enable double clicking from the

                                            // Macintosh Finder or the Windows Explorer

                                            #target photoshop

                                             

                                            // Make Photoshop the frontmost application

                                            app.bringToFront();

                                             

                                            /////////////////////////

                                            // SETUP

                                            /////////////////////////

                                             

                                             

                                            var html = "";

                                            var request = "";

                                            var url = "";

                                            var binary = "";

                                            var requesthtml = "";

                                            var socket = new Socket;

                                            var domain = "www.mouseprints.net" // the domain for the file we want

                                            var sImg = "/old/dpr/JJMack8btiSrgb.png"; // the rest of the url for the file we want

                                            var port = ":80"; // the port for the file we want

                                            var url = prompt("Enter the image's full URL http://domain/full image path",url);   // prompt for domain name

                                            if (url != null){

                                                      if ( (url.indexOf("http://") != -1)  || (url.indexOf("HTTP://") != -1)  ) {

                                                                domainPathLength = url.length - "http://".length;

                                                                domainPath = url.substr(7, domainPathLength);

                                                                pathOffset = domainPath.indexOf("/");

                                                                domain = domainPath.substr(0, pathOffset);

                                                                sImg = domainPath.substr(pathOffset, domainPath.length - pathOffset );

                                                                // Isolate Image name

                                                                var Name =  sImg

                                                                var imagePath = "";

                                                                while (Name.indexOf("/") != -1 ) {                                        // Strip Path

                                                                          imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);

                                                                          Name = Name.substr(Name.indexOf("/") + 1 ,);

                                                                          }

                                                      }

                                            }

                                            //alert("domain = " +  domain + " , Image = " + sImg );

                                             

                                             

                                             

                                            /////////////////////////

                                            // MAIN

                                            /////////////////////////

                                            //var f = File("~/socket_sample_" + sImg.substr(sImg.length-4)); // 4 = Image extension .gif or .jpg ...

                                            var f = File("~/" + Name); // Image file name

                                            f.encoding = "binary"; // set binary mode

                                            f.open("w");

                                             

                                             

                                            if (socket.open(domain + port, "binary")){

                                                      //alert("GET " + sImg +" HTTP/1.0\n\n");

                                                      requesthtml ="\n\nDmain:" + domain + " Port" + port + " binary\n"

                                                      request ="GET " + sImg +" HTTP/1.0\n\n"

                                                      socket.write(request); // get the file

                                                      var binary = socket.read(99999999);

                                                      binary = removeHeaders(binary);

                                                      f.write(binary);

                                                      socket.close();

                                            } else { alert("Connection to Domain:" + domain + " Port" + port + " Failed   ");}

                                             

                                             

                                            f.close();

                                             

                                             

                                            if (binary.length != 0) {

                                                      //alert ("file length = " + binary.length );

                                             

                                             

                                                      if(app.documents.length == 0) {

                                                                //app.documents.add(new UnitValue(200,'px'), new UnitValue(200,'px'), 72, 'Untitled 1' );

                                                                // =======================================================

                                                                var idMk = charIDToTypeID( "Mk  " );

                                                                    var desc1 = new ActionDescriptor();

                                                                    var idNw = charIDToTypeID( "Nw  " );

                                                                        var desc2 = new ActionDescriptor();

                                                                        var idMd = charIDToTypeID( "Md  " );

                                                                        var idRGBM = charIDToTypeID( "RGBM" );

                                                                        desc2.putClass( idMd, idRGBM );

                                                                        var idWdth = charIDToTypeID( "Wdth" );

                                                                        var idRlt = charIDToTypeID( "#Rlt" );

                                                                        desc2.putUnitDouble( idWdth, idRlt, 3504.000000 );

                                                                        var idHght = charIDToTypeID( "Hght" );

                                                                        var idRlt = charIDToTypeID( "#Rlt" );

                                                                        desc2.putUnitDouble( idHght, idRlt, 2336.000000 );

                                                                        var idRslt = charIDToTypeID( "Rslt" );

                                                                        var idRsl = charIDToTypeID( "#Rsl" );

                                                                        desc2.putUnitDouble( idRslt, idRsl, 72.000000 );

                                                                        var idpixelScaleFactor = stringIDToTypeID( "pixelScaleFactor" );

                                                                        desc2.putDouble( idpixelScaleFactor, 1.000000 );

                                                                        var idFl = charIDToTypeID( "Fl  " );

                                                                        var idFl = charIDToTypeID( "Fl  " );

                                                                        var idWht = charIDToTypeID( "Wht " );

                                                                        desc2.putEnumerated( idFl, idFl, idWht );

                                                                        var idDpth = charIDToTypeID( "Dpth" );

                                                                        desc2.putInteger( idDpth, 8 );

                                                                        var idprofile = stringIDToTypeID( "profile" );

                                                                        desc2.putString( idprofile, "sRGB IEC61966-2.1" );

                                                                    var idDcmn = charIDToTypeID( "Dcmn" );

                                                                    desc1.putObject( idNw, idDcmn, desc2 );

                                                                executeAction( idMk, desc1, DialogModes.NO );

                                                      }

                                             

                                             

                                                      placeSmartObject( f );

                                            }

                                             

                                             

                                            f.remove(); // Remove temporary downloaded files

                                             

                                             

                                             

                                            /////////////////////////

                                            // FUNCTIONS

                                            /////////////////////////

                                            function placeSmartObject(fileRef){

                                                      //create a new smart object  layer using a file

                                                      try {

                                                                var desc = new ActionDescriptor();

                                                                          desc.putPath( charIDToTypeID( "null" ), new File( fileRef ) );

                                                                          desc.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ),charIDToTypeID( "Qcsa" ));

                                                                          desc.putUnitDouble( charIDToTypeID( "Wdth" ),charIDToTypeID( "#Prc" ), 100 );

                                                                          desc.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Prc" ), 100 );

                                                                          desc.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0 );

                                                                          desc.putBoolean( charIDToTypeID( "Lnkd" ), true );

                                                                executeAction( charIDToTypeID( "Plc " ), desc, DialogModes.NO );

                                                                activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);

                                                                activeDocument.revealAll();

                                                      } catch (e) {

                                                                if (!e.toString().match(/Place.+is not currently available/)) {

                                                                          throw e;

                                                                }

                                                      }

                                            };

                                             

                                             

                                            // Remove header lines from HTTP response

                                            function removeHeaders(binary){

                                                      var bContinue = true ; // flag for finding end of header

                                                      var line = "";

                                                      var httpheader = "";

                                                      var nFirst = 0;

                                                      var count = 0;

                                                      while (bContinue) {

                                                                line = getLine(binary) ; // each header line

                                                                httpheader = httpheader + line;

                                                                bContinue = line.length >= 2 ; // blank header == end of header

                                                                nFirst = line.length + 1 ;

                                                                binary = binary.substr(nFirst) ;

                                                      }

                                                      if (httpheader.indexOf("Bad Request") != -1 || httpheader.indexOf("Not Found") != -1) {

                                                                alert (requesthtml + request + httpheader);

                                                                var binary = "";

                                                      }

                                                      //alert (requesthtml + request + httpheader + "\nFile length = " + binary.length);

                                                      return binary;

                                            };

                                             

                                            // Get a response line from the HTML

                                            function getLine(html){

                                                      var line = "" ;

                                                      for (var i = 0; html.charCodeAt(i) != 10; i++){ // finding line end

                                                                line += html[i] ;

                                                      }

                                                      return line ;

                                            };

                                             

                                            • 20. Re: Get file from ftp
                                              Michael L Hale Level 5

                                              Not sure why you added the comment that I modifed Jeff's script. I posted it as I found it with the exception of a comment that the URL may no longer be valid.

                                              • 21. Re: Get file from ftp
                                                JJMack Most Valuable Participant

                                                The older we get the quicker we forget things we did and posted. This Script is not Jeffs script that you posted in this thread  that transfers the images opens it as a document Photoshop and deletes the transfered file. Its a modified version you posted in an other thread that Place in the web image as smart object lyer into the current active docment or a new document the script adds. I added some mods that I wanted to it. Its very easy to create a collage or composit of several images found on the web you just need to use it for each image you just paste in the URL. I'm just a hacker If someone places their name in a script and other add their mods I leave in things like

                                                // Written by Jeffrey Tranberry

                                                // Photoshop for Geeks Version 3.0

                                                // modified by MLH

                                                There since my mods were made in 2010 I would think you made the post only a year ago at my age its hard to remenber a year ago thing 30 and 50 years ago sometime see like yesterday how fast time passes by. Found your post http://forums.adobe.com/message/2922142#2922142

                                                 

                                                People like you and Paul make a hackers life easy and lazy.  Thank a bunch

                                                 

                                                BUNCH those letters seem to ring a bell in my brain.

                                                 

                                                Google found it http://www.acronymfinder.com/Burroughs,-UNIVAC-(Sperry),-NCR,-CDC,-%26-Honeywell-(BUNCH).h tml

                                                 

                                                The Burroughs Corporation was a major American manufacturer of business equipment. The company was founded in 1886 as the American Arithmometer Company and was assimilated in the 1986 merger that resulted in the creation of Unisys. The company's history paralleled many of the major developments in computing. At its start it produced mechanical adding machines, and later moved into programmable ledgers and then computers. And while it was one of the largest producers of mainframe computers in the world, Burroughs also produced related equipment as well, including typewriters and printers.

                                                 

                                                The UNIVAC I (UNIVersal Automatic Computer I) was the first commercial computer produced in the United States. (The first commercial computer in the world, was the Ferranti Mark 1, which was delivered to the University of Manchester, UK in February 1951.) It was designed principally by J. Presper Eckert and John Mauchly, the inventors of the ENIAC. Design work was begun by their company, Eckert-Mauchly Computer Corporation, and was completed after the company had been acquired by Remington Rand (which later became part of Sperry, now Unisys). In the years before successor models of the UNIVAC I appeared, the machine was simply known as "the UNIVAC".

                                                The first UNIVAC was delivered to the United States Census Bureau on March 31, 1951, and was dedicated on June 14 that year.[1] The fifth machine (built for the U.S. Atomic Energy Commission) was used by CBS to predict the result of the 1952 presidential election. With a sample of just 1% of the voting population it correctly predicted that Dwight Eisenhower would win.

                                                 

                                                NCR Corporation (NYSE: NCR) is an American technology company specializing in kiosk products for the retail, financial, travel, healthcare, food service, entertainment, gaming and public sector industries. Its main products are self-service kiosks, point-of-sale terminals, automated teller machines, check processing systems, barcode scanners, and business consumables. They also provide IT maintenance support services. From 1988 to 1997 they sponsored the NCR Book Award for non-fiction. NCR had been based in Dayton, Ohio, starting in 1884, but in June 2009, the company sold most of the Dayton properties and moved its headquarters to Metro Atlanta. Currently the headquarters are in unincorporated Gwinnett County, Georgia, near Duluth.[5][6]

                                                The company was founded in 1884 and acquired by AT&T in 1991. A restructuring of AT&T in 1996 led to NCR's re-establishment on 1 January 1997 as a separate company, and involved the spin-off of Lucent Technologies from AT&T. NCR is the only AT&T acquisition that retained its original name – all the others have either been purchased or renamed following subsequent mergers.

                                                 

                                                Control Data Corporation (CDC) was a supercomputer firm. For most of the 1960s, it built the fastest computers in the world by far, only losing that crown in the 1970s after Seymour Cray left the company to found Cray Research, Inc. (CRI). CDC was one of the nine major United States computer companies through most of the 1960s; the others were IBM, Burroughs Corporation, DEC, NCR, General Electric, Honeywell, RCA, and UNIVAC. CDC was well known and highly regarded throughout the industry at one time.

                                                 

                                                Honeywell International, Inc. (NYSE: HON) is a major conglomerate company that produces a variety of consumer products, engineering services, and aerospace systems for a wide variety of customers, from private consumers to major corporations and governments.

                                                Honeywell is a Fortune 100 company with a workforce of approximately 130,000, of which approximately 58,000 are employed in the United States.[2] The company is headquartered in Morristown, New Jersey. Its current chief executive officer is David M. Cote. The company and its corporate predecessors were part of the Dow Jones Industrial Average Index from December 7, 1925 until February 9, 2008.

                                                 

                                                Yes I'm a Dinosaur NOT Dead Yet...........................................

                                                 

                                                Message was edited by: JJMack

                                                • 22. Re: Get file from ftp
                                                  Michael L Hale Level 5

                                                  I guess you are right - I am getting old. I have no memory of making that post or those edits. I guess that I some times knock out a script to answer a question and then forget it after posting.

                                                  • 23. Re: Get file from ftp
                                                    JJMack Most Valuable Participant

                                                    Cleaned up my script url parsing and also modified Adobe Sample script Socket.jsx http://mouseprints.net/old/dpr/StackWebPageImages.jsx

                                                    and http://mouseprints.net/old/dpr/OpenImageFromWeb.jsx

                                                    • 24. Re: Get file from ftp
                                                      ThePromenader

                                                      Hello,

                                                       

                                                      First off, thanks a mill for your script - very informative (and useful!). I'd just like to add one note though about:

                                                      var binary = socket.read(9999999);

                                                      ...because if you're running from a script written in the ExtendScript Toolkit (CS 5.1 for me), the script will hang until the '9999999' times out. A quick solution is to call ~another~ empty socket read :

                                                      var binary = socket.read();

                                                      ...just before you call socket.close().

                                                       

                                                      I'm still wondering if there is a more 'elegant' way of maintaining an open connection while the file reads/writes... a 'while(socket.connected)' loop? I'm still new to this, but I'll post if I find another method.

                                                       

                                                      Thanks again!

                                                      • 25. Re: Get file from ftp
                                                        ThePromenader Level 1

                                                        SORRY! The '9999999' is ~not~ the reason ExtendScript Toolkit is hanging - and it does not hang consistently, either. Something in there is making it hang (perhaps only for my version), it hasn't happened before...