VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   File Transfer (https://forums.vandyke.com/forumdisplay.php?f=18)
-   -   Javascript SFTP Tab (https://forums.vandyke.com/showthread.php?t=12935)

mschaafs 12-08-2017 02:16 PM

Javascript SFTP Tab
 
Good day... I am trying to open a new tab via Javascript for SFTP. I have used the vbscript guide example as a basis, but it is not working. It would be great if there were a version of that guide in JS to use!
In any case, here is what I have, any insights would be greatly appreciated!

Code:

// SFTP test
var objTab;
var objSFTPTab;
objTab = crt.Session.ConnectInTab("/S");
//objTab.Caption = "New SFTP Tab";

// Create an SFTP tab associated with the existing tab
objSFTPTab = objTab.ConnectSFTP();

// Wait for the SFTP tab to be ready for input.
objSFTPTab.Screen.Synchronous = true;
crt.Sleep(1000);
objSFTPTab.Screen.Send(String.fromCharCode(13));
objSFTPTab.Screen.WaitForString("sftp>");

// Upload all .txt files in the current local working directory to
// the current remote working directory.
objSFTPTab.Screen.Send("put *.txt" + String.fromCharCode(13) + String.fromCharCode(10));
objSFTPTab.Screen.WaitForString("sftp>");

// Close the SFTP tab
objSFTPTab.Close();
// Close the connection on the originating SSH2 connection's tab
objTab.Session.Disconnect();


bgagnon 12-08-2017 02:55 PM

Hi mschaafs,

What version of SecureCRT are you using?

On what platform/OS?

Your code worked for me with one minor change. You are not specifying a session to be opened. If you want to just make an ad hoc connection, then use /SSH2 hostname instead of /S SessionName:

Code:

objTab = crt.Session.ConnectInTab("/S SessionName");

I am not sure a manual on JScript is ever feasible (Python would be the next one up), but I have added this thread to a feature request in our product enhancement database for more JavaScript examples. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #12935" in the subject line or use this form from the support page of our website.

mschaafs 12-08-2017 03:20 PM

It's alive!
 
Yes! Thank you Brenda... Using a new login connection worked... but now I have to deal with the password, but I will get that figured out.
I am using version 8.1.4 build 1443. One weird thing I am seeing, is that I have to send a command that appears not to be working in order to send one that does work. See below, I have the 'lpwd' command being sent twice, because the first one doesn't show up. Also, is there a command to force a disconnect without a prompt?

Code:

// SFTP test
var objTab;
var objSFTPTab;
objTab = crt.Session.ConnectInTab("/SSH2 /L user /PASSWORD pw host");
objTab.Caption = "Connection Tab";
objTab.Screen.Synchronous = true;

// Create an SFTP tab associated with the existing tab
objSFTPTab = objTab.ConnectSFTP();
objSFTPTab.Caption = "SFTP Tab";
objSFTPTab.Screen.Synchronous = true;
crt.Sleep(1000);

// Wait for the SFTP tab to be ready for input.
objSFTPTab.Screen.Send(String.fromCharCode(13));
objSFTPTab.Screen.WaitForString("sftp>");

// Send extra command to prompt to activate, for whatever reason... is required.
objSFTPTab.Screen.Send("lpwd" + String.fromCharCode(13));
objSFTPTab.Screen.WaitForString("sftp>");

objSFTPTab.Screen.Send("lpwd" + String.fromCharCode(13));
objSFTPTab.Screen.WaitForString("sftp>");

objSFTPTab.Screen.Send("lcd newLocalPath" + String.fromCharCode(13));
objSFTPTab.Screen.WaitForString("sftp>");

objSFTPTab.Screen.Send("get fileNameHere" + String.fromCharCode(13));
objSFTPTab.Screen.WaitForString("sftp>");

// Close the SFTP tab
objSFTPTab.Close();
// Close the connection on the originating SSH2 connection's tab
objTab.Session.Disconnect();
objTab.Close();


bgagnon 12-08-2017 03:28 PM

Hi mschaafs,

Quote:

but now I have to deal with the password, but I will get that figured out.
I am not sure what you mean by that. I see you have added user/password options to the SSH2 command string.


Quote:

One weird thing I am seeing, is that I have to send a command that appears not to be working in order to send one that does work.
Not sure about this, my results were not the same. Let's see where this issue stands after the others are sorted.


Quote:

Also, is there a command to force a disconnect without a prompt?
Disable Show confirm disconnect dialog in the General category of Global Options.

bgagnon 12-08-2017 03:45 PM

Hi mschaafs,

I took out the extra lpwd and get everything just as expected (I had commented out the disconnect/close):

Code:

sftp>
sftp> lpwd
C:\Users\user\Documents
sftp> lcd ..
sftp> get testfile.txt
Downloading testfile.txt from /home/user/testfile.txt
  100% 38KB    38KB/s 00:00:00   
/home/user/testfile.txt: 39596 bytes transferred in 0 seconds (38 KB/s)
sftp>

Do you get the same results when you do the steps manually?

mschaafs 12-08-2017 03:56 PM

Thank you!
 
Hi! Thank you gain for the speedy response!

One weird thing I am seeing, is that I have to send a command that appears not to be working in order to send one that does work.
Quote:

Not sure about this, my results were not the same. Let's see where this issue stands after the others are sorted.
Tried it again, and it is working now. Not sure what I did that changed it, but sweet!

Quote:
Also, is there a command to force a disconnect without a prompt?
Quote:

Disable Show confirm disconnect dialog in the General category of Global Options.
I was looking for a command to suppress this dialog, does that exist? So the user doesn't have to confirm in the middle of my automated process?

bgagnon 12-11-2017 07:02 AM

Hi mschaafs,

Quote:

I was looking for a command to suppress this dialog, does that exist? So the user doesn't have to confirm in the middle of my automated process?
I'm confused by your response. If you disable the option mentioned, the dialog will be suppressed.

mschaafs 12-11-2017 07:50 AM

Clarification
 
Hello Brenda! Thank you again for the response... I mean, I am building a program that is going to be distributed to all our folks, and I want a programmatic (non-manual setting) way to suppress the disconnect dialog. So that those I send this to do not each have to go in and change the setting before running it. Does that make more sense?

bgagnon 12-11-2017 07:56 AM

Hi mschaafs,

Unfortunately, there is not, as it is an option in Global Options. Presently only Session Options are configurable through scripting (via SessionConfiguration object).

I have added this thread to a feature request in our product enhancement database to allow configuration of Global Options from a script API call. Should a future release of SecureCRT include this feature, notification will be posted here.

If you prefer direct email notification, send an email to support@vandyke.com and include "Feature Request - Forum Thread #12935" in the subject line or use this form from the support page of our website.

So the alternative now would just be to make sure all users have a Global.ini file (corresponding to Global Options) where the option has been disabled.

mschaafs 12-11-2017 08:57 AM

Thank you much!
 
Sounds good! I am grateful for all the help and responsiveness! Happy holidays to you.

bgagnon 02-22-2019 10:09 AM

Hi mschaafs,

The ability to configure Global Options via scripting has been added to a pre-release version of SecureCRT.

If you are interested in trying the new build, please send an email to support@vandyke.com and include "GlobalConfig feature request" in the subject line. If not writing us from the email address associated with your VanDyke Software download account, please include it in the body of your email.


All times are GMT -6. The time now is 09:58 PM.