Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > File Transfer

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2017, 02:16 PM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 26
Question 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();
Reply With Quote
  #2  
Old 12-08-2017, 02:55 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,902
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 12-08-2017, 03:20 PM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 26
Talking 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();
Reply With Quote
  #4  
Old 12-08-2017, 03:28 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,902
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by bgagnon; 12-08-2017 at 03:41 PM.
Reply With Quote
  #5  
Old 12-08-2017, 03:45 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,902
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?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 12-08-2017, 03:56 PM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 26
Thumbs up 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?
Reply With Quote
  #7  
Old 12-11-2017, 07:02 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,902
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #8  
Old 12-11-2017, 07:50 AM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 26
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?
Reply With Quote
  #9  
Old 12-11-2017, 07:56 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,902
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #10  
Old 12-11-2017, 08:57 AM
mschaafs mschaafs is offline
Registered User
 
Join Date: Oct 2017
Posts: 26
Thumbs up Thank you much!

Sounds good! I am grateful for all the help and responsiveness! Happy holidays to you.
Reply With Quote
  #11  
Old 02-22-2019, 10:09 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,902
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by bgagnon; 02-22-2019 at 10:22 AM.
Reply With Quote
Reply

Tags
file transfer , javascript , scripting , session tabs , sftp


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:10 PM.