0

I have a doubt (classic-asp server).

This script:

<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
  function executeCommands()
   {
          var WshShell = new ActiveXObject("WScript.Shell");
          var sFTP = 'ftp.exe -s:\\\\aServerNas.intranet.blalba\\scossa$\\\\ftp\\<%=CODEID%>.ftp';   
          var oExec = WshShell.run(sFTP , 2);             
  };
</SCRIPT>

allow me to run the ftp script in a side-client (my pc) command shell when I click on id=reload tag:

$('#reload').click(function(){
        executeCommands();
    }
});

But if I change the script adding attribute "runat":

<SCRIPT type="text/javascript" LANGUAGE="JavaScript" runat="server">
  function executeCommands()
   {
          var WshShell = new ActiveXObject("WScript.Shell");
          var sFTP = 'ftp.exe -s:\\\\aServerNas.intranet.blalba\\scossa$\\\\ftp\\<%=CODEID%>.ftp';   
          var oExec = WshShell.run(sFTP , 2);             
  };
</SCRIPT>

the command-shell, when I click on id=reload tag, will be executed on the server (\\aServerNas), which is what I need?

Thank you a lot and I apologize for my bad english.

Edit: the question is: How I can run FTp if client-side havn't access to \aServerNas (that is the server where the .ftp script is)?

4
  • Is your $('#reload').click(function(){... code still on the client side, because if it is it won't be able to see the server side function. Server side code is executed on the server (as the name suggests) and runs as the page is loading. Rather than trying to call a function you would probably be better off putting your code inside a conditional statement which is triggered by a form submission or a querystring value. Commented Feb 9, 2016 at 10:51
  • Hello, code (jquery) is on a .js page that is on server along with the .asp page that contains <script type="text/javascript" src="scriptDiscrimina.js"></script>. The function executeShell() is on the same .asp page. Commented Feb 9, 2016 at 11:15
  • So it's client side js. You're trying to execute your function on the browser and the browser can't see it because it's server side. Commented Feb 9, 2016 at 11:19
  • Thank you for your attention. The question, in essence, is: How can client run FTP script if he hasn't access to \\aServerNas (that is the server where the .ftp script is)? No way? Commented Feb 9, 2016 at 11:22

1 Answer 1

0

Try something like this, I've used vbs rather than js because that's what I'm familiar with

<%
If request.form("CODEID") <> "" then
  dim WshShell, sFTP, CODEID
  CODEID = request.form("CODEID")
  set WshShell = CreateObject("WScript.Shell")
  sFTP = "ftp.exe -s:\\aServerNas.intranet.blalba\scossa$\\ftp\" & CODEID & ".ftp" 
  WshShell.Exec(sFTP , 2)  
End If
%>

I'm assuming here that you're posting the value of CODEID in a form. Note that you can't use <%=CODEID%> within server side code. The <% %> delimiters denote that what they contain is for the server, so using them twice is nonsense.

You might find this question helpful - Running VBS script on server from IIS (ASP)

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, I'll try this as soon as possible.
I have tried(*), but it "does nothing": no error but file isn't transfered ... :-( *: set WshShell = Server.CreateObject("WScript.Shell") sFTP = "ftp.exe -s:\\aServerNas.intranet.blalba\scossa$\ftp\" & CODEID & ".ftp" WshShell.Exec sFTP 'tried also: 'WshShell.run sFTP
@scossa Because it's executed against the server you don't see any output but because you are using WshShell.Exec() you should be able to check the .StdOut stream to get the output from the command.
I have checked remote dir (via local ftp) and the file is not present. @Lankymart: how to? wshShell.StdOut ? an example pls, tnks.
@Lankymart: tnks, I tried, .STATUS return 0 and Exit Code return 0; file transfer is not executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.