upload file to FTP

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Patrick

upload file to FTP

Post by Patrick »

I wrote this awhile back to upload files to a webserver at the end of the script that prepped them for the web. This is just cut and paste from my script so you may have to do some cleanup to remove my script-specific references. This was written for use on a Windows machine, as the commands are for the command line FTP that comes with Windows.

Code: Select allfunction BatchDefaults(ftpip,ftplogin,ftppass)
{
   try
   {
      // fix users save path to be windows format
      var slashes = new RegExp("\/","g");
      var fspath = savePath.replace(slashes,"/");
      var bspath = savePath.replace(slashes,"\\");

      // build ftp command file
      var txt = new File(fspath + "/psupload.txt");
      txt.open("w");
      txt.writeln(ftplogin);
      txt.writeln(ftppass);
      txt.writeln("prompt");
      txt.writeln("cd products");

      // write a line for every file you want to upload
      txt.writeln("send \"" + fspath + prodName + "_1.jpg\"");
      txt.writeln("send \"" + fspath + prodName + "_2.jpg\"");
      txt.writeln("send \"" + fspath + prodName + "_3.jpg\"");
      txt.writeln("send \"" + fspath + prodName + "_4.jpg\"");
      txt.writeln("send \"" + fspath + prodName + "_5.jpg\"");

      txt.writeln("close");
      txt.writeln("quit");
      txt.close();

      // build batch file
      var bat = new File(fspath + "/psupload.bat");
      bat.open("w");
      bat.writeln("ftp -s:\"" + bspath + "psupload.txt\" " + ftpip);   // run ftp upload
      bat.writeln("del \"" + bspath + "psupload.txt\"");   // delete ftp txt file
      bat.close();
         
      // run batch file
      bat.execute();
   }
    catch (e)
    {   // display error
      alert("Problem bulding FTP batch file! \r\r" + e);
    }
};
v.bampton

upload file to FTP

Post by v.bampton »

Handy script Patrick! Anyone know if the same idea can work on a Mac?
xbytor

upload file to FTP

Post by xbytor »

The Mac can handle stuff like this pretty easily but you have to use a slightly different technique. I'll post up a solution in a couple of days.

-X
v.bampton

upload file to FTP

Post by v.bampton »

Thanks X & Patrick - I never even considered that I could FTP from a PS Script, but I've got just the use for it!
Andrew

upload file to FTP

Post by Andrew »

This looks great - how does one deal with files that need binary / ascii upload. Can it also deal with folder upload - I would like to pass an array of file and folder targets and have them all uploaded while replicating the original folder structure (which may be multi-layered).

Andrew
xbytor

upload file to FTP

Post by xbytor »

ftp, the underlying app, has a binary/ascii mode toggler ('bin', if I remember correctly).

-X