Skip to main content
Known Participant
July 31, 2007
Question

FtpConnection and palette window problem

  • July 31, 2007
  • 3 replies
  • 871 views
I've tried to implement a progress bar for handling FtpConnection puts and gets.
My progress bar code works; I use it in PSCS2 and PSCS3 just fine. My ftp code
is also working in Bridge CS3: my progress bar and text is getting updated
correctly, the files are getting transferred, I am just locked out of doing
anything with it, like hit the cancel key.

I've tried doing this with ftp sync and async, I've pumping and not pumping.
Nothing I do will let the palette window acquire focus while FtpConnection is
doing a get or a put.

Has anybody got a progress bar/palette working with FtpConnection yet?


-X
This topic has been closed for replies.

3 replies

Participating Frequently
August 1, 2007
No probs :)
Participating Frequently
August 1, 2007
Hi,

You can create a scheduled task and call pump() on the ftp object from within that, then use the ftp call back to update your progress bar. With the Asynch demo Bridge/dialog will lock because the main thread is sleeping and writing to the console inside the while loop.

Try the following, you will have to adjust the timings and what not to get exactly what you are after but this works. I 'quickly' tested with a 100mb zip file using Bridge/ESTK CS3 and plain old ftp server.

Make sure a selection is made in Bridge and then run the script from ESTK - hope it helps.

Cheers,

// Load the webaccess library
if( webaccesslib == undefined )
{
if( Folder.fs == "Windows" ) {
var pathToLib = Folder.startup.fsName + "/webaccesslib.dll";
} else {
var pathToLib = Folder.startup.fsName + "/webaccesslib.bundle";
// verify that the path is valid
}
var libfile = new File( pathToLib );
var webaccesslib = new ExternalObject("lib:" + pathToLib );
}


// Create the progress dialog
var win = new Window("palette", "FTP Dialog");

// Add a panel to contain the components
win.pnl = win.add("panel", undefined, "FTP Status");
// Add a progress bar with a label and initial value of 0, max value of 100.
var pBar = win.pnl.add("progressbar", undefined, 0, 100);

// Add buttons
win.cancelButton = win.add("button", undefined, "Cancel");

win.cancelButton.onClick = function()
{
$.writeln("FTP Cancelled");
ftpServer.cancel();
app.cancelTask(MyTask.id);
win.close();
}

// This task will be scheduled to control the progress bar upddate
MyTask = {};
MyTask.id = 0;
MyTask.updateStatus = function()
{
//$.writeln("updateStatus() called");
ftpServer.pump();
}

var ftpAddress = "";
var ftpUsername = "";
var ftpPassword = "";
var ftpDir = "";

// Create ftp object and assign username/password
var url = "ftp://" + ftpAddress;

var ftpServer = new FtpConnection(url);
ftpServer.timeout = 30;

// We don't want a blocking connection
ftpServer.async = true;

ftpServer.username = ftpUsername;
ftpServer.password = ftpPassword;

ftpServer.onCallback = function(reason,p_log,total)
{
if(reason == FtpConnection.reasonProgress)
{
pBar.value += 10;
}

if( reason == FtpConnection.reasonStart ) {
$.writeln("AsyncFTP: Upload started");
}

if( reason == FtpConnection.reasonComplete ) {
$.writeln("AsyncFTP: Upload finished");
app.cancelTask(MyTask.id);
win.close();
}

if(reason == FtpConnection.reasonFailed ) {
$.writeln("AsyncFTP: Upload failed");
app.cancelTask(MyTask.id);
win.close();
}
}

ftpServer.open(url);
if(ftpServer.isOpen)
{
// Move to a directory (if needed)
ftpServer.cd = "bridge"

// Create the destination directory on the server
//ftpServer.mkdir(ftpDir);

// Move to the new directory
ftpServer.cd = ftpDir;

if(app.document.selections.length == 1)
{
win.show();
// The selected thumbnails in Bridge
var sels = app.document.selections;
ftpServer.put(sels[0].spec, sels[0].name);

// Rerun this task every 100 ms
MyTask.id = app.scheduleTask("MyTask.updateStatus()", 100, true);
}
}

"End"
_xbytor_Author
Known Participant
August 1, 2007
Chanandler_Bong@adobeforums.com wrote:
> Hi,
>
> You can create a scheduled task and call pump() on the ftp object from within that, then use the ftp call back to update your progress bar.

Ahhhh. There is the bit of info that I needed. I was looking for something like
this and didn't recognize it for what it was.

> With the Asynch demo Bridge/dialog will lock because the main thread is sleeping and writing to the console inside the while loop.

I figured that this was what was happening. With palette windows in PS, you can
do some concurrent processing and not completely lock out the palette window.
Bride is slightly different.

>
> Try the following, you will have to adjust the timings and what not to get exactly what you are after but this works. I 'quickly' tested with a 100mb zip file using Bridge/ESTK CS3 and plain old ftp server.

My code will be uploading a series of files, but it should behave the same.

>
> Make sure a selection is made in Bridge and then run the script from ESTK - hope it helps.

I'll get my code converted over today and report back. Thanks for the help.

-X
_xbytor_Author
Known Participant
August 1, 2007
xbytor@adobeforums.com wrote:

> I'll get my code converted over today and report back. Thanks for the help.

My code is converted and working like a charm! Thanks again for the help.

-X
_xbytor_Author
Known Participant
July 31, 2007
I took another pass at this by splicing AsynchronousFTP.jsx and
SnpCreateProgressBar.jsx.

I'm still seeing the same problem. The progress bar palette will be visible and
update correctly, it will just also be locked out from receiving any user input,
so I have no (sane) way of disabling the ftp transfer.

Am I doing something wrong or is this just not possible?

-X