WinSCP and ASCII_RECSEP - ftp

What's the equivalent in WinSCP for this command:
quote "SITE ASCII_RECSEP=NONE"
Is it just -transfer=binary when using put command or it's something completely different?
From what I read it says like it's related to FTP streaming behavior. And it looks like this quote is used just to execute this SITE command on remote FTP server. But I'm not sure how to change my builtin FTP script (that part that I mentioned above) to work with WinSCP.
It looks like I need to use this call command?
https://winscp.net/eng/docs/scriptcommand_call

Yes, use the call command:
call SITE ASCII_RECSEP=NONE
With the FTP protocol, the WinSCP call command is an equivalent of the literal command (and its quote alias) of the Windows ftp.exe.
See a section on the literal command in the guide for converting Windows FTP script to WinSCP script.
And follow the quide for other issues you may encounter, when converting your script.

Related

Creating a GUI to interact with Putty

I have to build one application which on button click starts passing command with putty.exe how can it be done with process.start ?
Process.start(#"C:\putty.exe")
ProcessStartInfo startinfo = new ProcessStartInfo();
startInfo.FileName=#"C:\putty.exe"
startInfo.Arguments = "some load session";
this is my current code but i want to push certain script and commands to putty terminal as well
It looks like PuTTY's command line support is rather minimal, but the -m option may work:
From http://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter3.html#using-cmdline
3.8.3.6 -m: read a remote command or script from a file
The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
You'll have to put your command(s) in a file before and pass that to PuTTY, but for simple tasks, it could work.
As mentioned in a comment on the question, Plink sounds much more amenable to what you're trying to do, as it (appears to) support a fully interactive session via the StandardInput and StandardOutput properties on the object you'll get back from Process.Start().

How Secure is using execFile for Bash Scripts?

I have a node.js app which is using the child_process.execFile command to run a command-line utility.
I'm worried that it would be possible for a user to run commands locally (a rm / -rf horror scenario comes to mind).
How secure is using execFile for Bash scripts? Any tips to ensure that flags I pass to execFile are escaped by the unix box hosting the server?
Edit
To be more precise, I'm more wondering if the arguments being sent to the file could be interpreted as a command and executed.
The other concern is inside the bash script itself, which is technically outside the scope of this question.
Using child_process.execFile by itself is perfectly safe as long as the user doesn't get to specify the command name.
It does not run the command in a shell (like child_process.exec does), so there is no need to escape anything.
child_process.execFile will execute commands with the user id of the node process, so it can do anything that user could do, which includes removing all the server files.
Not a good idea to let user pass in command as you seem to be implying by your question.
You could consider running the script in a sandbox by using chroot, and limiting the commands and what resides on the available file system, but this could get complet in a hurry.
The command you pass will get executed directly via some flavor of exec, so unless what you trying to execute is a script, it does not need to be escaped in any way.

how to ftp remote server through running a shell script

ftp ipaddress
bin
hash
cd path
get filename
quit
i want these line to be executed in a shell script only first line is executing after entering username and password the rest line are not executing and the control is stuck at ftp> prompt
Once your script invokes the program ftp, the shell loses control until the ftp program finishes. So you need to use some new technique. One way is with the program expect, which you can get a hint about here: https://stackoverflow.com/a/12598169/4323 . Another way is to use a more "scriptable" FTP client, such as lftp on Linux, which has specific features to enable the sort of scripted use you're going for.
You need to use a non-interactive FTP client if you want to do this in a script rather than an interactive shell. ncftp is one you could check out.
Or you can use a shell "here" document:
#!/bin/bash
ftp -in <<EOS
user pswd
bin
hash
cd path
get filename
quit
EOS
The here document sends everything via the open program's stdin, just as if you typed it in at the command line. Note that ftp clients can be finicky and each one seems to have it's own set of gotchas, so some experimentation and use of man ftp will likely be required.
Looks like this has come up before on Stackoverflow, you might want to read through
how to ftp multiple file using shell script
IHTH

While Using PLink Only First Command Is Executing

I want to connect putty using plink and want to run some specific commands which is present in text file. But I can see only first command getting executed. Do I need to give any command separating literal?
I have this problem too. Solutions that I used.
Sending one line command with && or &
If script is big, send it with pscp and run on remote host with single command/
I beleive there is the third way. Just execute script under -m option :)

To read the output of a command in a shell script

I am running a unix command say ftp to a remote machine through a shell script.I have to pass the userid and password through the script accordingly.How can i do that?
Best way to supply username/passwords from scripts would be to use 'expect' scripting.
Here is a small example : http://www.linuxquestions.org/questions/linux-software-2/auto-ssh-login-expect-script-624047/
. It shows using expect to provide password for ssh, ftp should be very similar.
Redirect the ftp command inside your shell script
ftp ..... > ftp.log
Do you mean you want to get the result that the command (say, ftp) wrote to the terminal as a value inside the script?
Use backticks. For example:
x=`ftp ...`
will run the ftp command, and take the text of its stdout and store it in the variable x.

Resources