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);
}
};
upload file to FTP
upload file to FTP
Handy script Patrick! Anyone know if the same idea can work on a Mac?
upload file to FTP
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
-X
upload file to FTP
Thanks X & Patrick - I never even considered that I could FTP from a PS Script, but I've got just the use for it!
upload file to FTP
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
Andrew
upload file to FTP
ftp, the underlying app, has a binary/ascii mode toggler ('bin', if I remember correctly).
-X
-X