Nulling output echo'ed from FTP SERVER while authenticating.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Nulling output echo'ed from FTP SERVER while authenticating.

#1 Post by BoQsc » 01 May 2016 09:37

Simple FTP SERVER for windows to test the script quickly: ftpdmin.exe
  • Download
  • Double click ftpdmin.exe
  • launch this batch script


THE BATCH SCRIPT

Code: Select all

@echo off

SET "REMOTE_SERVER=localhost"
(ECHO ----------FTP COMMAND START---------------------
 
 ::Automaticaly typed input after launching Windows native FTP client (DELETE THIS COMMENT, CAUSE EITHER WAY - SCRIPT WONT WORK (HAVE NO CLUE WHY))
 (echo Administrator
    echo Password
       echo ls) | ftp %REMOTE_SERVER% )
ECHO ----------FTP COMMAND END---------------------
pause


I want to hide:
Login first with USER and PASS
User (localhost:(none)): Password:


output and just get ls commands output leftover.
Witch is for example:

----------FTP COMMAND START---------------------
acct
cache
config
d
data
dev
etc
flex
mnt
persist
proc
root
sbin
sdcard
sys
system
default.prop
init
init.goldfish.rc
init.qcom.rc
init.qcom.sh
init.rc
init.target.rc
ueventd.goldfish.rc
ueventd.rc
----------FTP COMMAND END---------------------



Instead of

----------FTP COMMAND START---------------------
Login first with USER and PASS
User (localhost:(none)): Password:

acct
cache
config
d
data
dev
etc
flex
mnt
persist
proc
root
sbin
sdcard
sys
system
default.prop
init
init.goldfish.rc
init.qcom.rc
init.qcom.sh
init.rc
init.target.rc
ueventd.goldfish.rc
ueventd.rc
----------FTP COMMAND END---------------------



Any ideas how i could achieve this?

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#2 Post by ShadowThief » 01 May 2016 19:01

Could you

Code: Select all

ftp %remoteserver% >nul
?

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#3 Post by BoQsc » 01 May 2016 23:40

ShadowThief wrote:Could you

Code: Select all

ftp %remoteserver% >nul
?

Yeah, but that is not what i really want. It hides whole output from

Code: Select all

ftp %remoteserver%

command including ls

I tried it before, I thought it is obvious so i didn't mention it in the post.
I need only to null first two lines of output that is caused by logging in.

Login first with USER and PASS
User (localhost:(none)): Password:


not the whole output from FTP command.


I wish i could just do this:

@echo off

SET "REMOTE_SERVER=localhost"
(ECHO ----------FTP COMMAND START---------------------

::Automaticaly typed input after launching Windows native FTP client (DELETE THIS COMMENT, CAUSE EITHER WAY - SCRIPT WONT WORK (HAVE NO CLUE WHY))
(echo Administrator >NUL
echo Password >NUL
echo ls) | ftp %REMOTE_SERVER% )
ECHO ----------FTP COMMAND END---------------------
pause


But that just clears the input commands sent to ftp server.


But thank you.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#4 Post by ShadowThief » 02 May 2016 00:31

I see that ftp has a -v flag that "suppresses display of remote server responses." It may do the same thing as >nul, but it's worth a try.

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#5 Post by BoQsc » 02 May 2016 01:47

ShadowThief wrote:I see that ftp has a -v flag that "suppresses display of remote server responses." It may do the same thing as >nul, but it's worth a try.


The -v is turning verbose mode on.



OUTPUT BEFORE-V FLAG APPLY wrote:Login first with USER and PASS
User (localhost:(none)): Password:
...


OUTPUT AFTER -V FLAG APPLY wrote:Connected to localhost.
220 JÅ«s prisijungete prie FTP serverio
530 Login first with USER and PASS
User (localhost:(none)): 331 Send password
Password:
230 Access granted
200 PORT OK
150 Opening ASCII mode data connection for file list
...


_______________________________________________________________________________________

Source http://ss64.com/nt/ftp.htmlis telling the wrong story about -v flag here.
Or i'm using it improperly, but it seems there is no other use than inside [-options] argument.


http://ss64.com/nt/ftp.html wrote:FTP

File Transfer Protocol. (Not Secure, for Secure FTP utilities see the links page.)

Syntax
FTP [-options] [-s:filename] [-w:buffer] [host]

key
-s:filename Run a text file containing FTP commands.
host Host name or IP address of the remote host.
-g Disable filename wildcards.
-n No auto-login.
-i No interactive prompts during ftp.
-v Hide remote server responses.
-w:buffer Set buffer size to buffer
(default=4096)
-d Debug
-a Use any local interface when binding data connection.



_______________________________________________________________________________________


Original code with -v flag that i tested:

Code: Select all

SET "REMOTE_SERVER=localhost"
(ECHO ----------FTP COMMAND START---------------------
 
 (echo Administrator
    echo Password
       echo ls) | ftp -v %REMOTE_SERVER% )
ECHO ----------FTP COMMAND END---------------------
pause

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#6 Post by BoQsc » 03 May 2016 01:54

So I found out that it is possible to filter the output using FOR loop, it is not that efficient compared to nulling output for sure, but I have no choice for now.
Right now I'm having a problem fitting the code I used previously:

I want to fit this:

Code: Select all

(echo Administrator
    echo Password
       echo ls) | ftp %REMOTE_SERVER%

Into For loop:

Code: Select all

::FTP Client Parser
FOR /F "delims=* USEBACKQ" %%O IN (`(echo Administrator echo Password echo ls^) ^| ftp %REMOTE_SERVER% `) DO ( ECHO %%O )


What I'm missing and is it possible to fit it into FOR LOOP?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#7 Post by foxidrive » 05 May 2016 11:15

BoQsc wrote:I want to hide:

Login first with USER and PASS
User (localhost:(none)): Password:



Is this an option?

Code: Select all

  echo ls) | ftp %REMOTE_SERVER% |findstr /i /v "user"

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#8 Post by BoQsc » 07 May 2016 08:28

foxidrive wrote:Is this an option?

Code: Select all

  echo ls) | ftp %REMOTE_SERVER% |findstr /i /v "user"


For now, it could be if there will be no further problems occur.

Here is the thing: The FTP client is automatically executing command OPTS UTF8 ON after every connection with a server.

The server has no such command as OPTS UTF8 ON, and inside client there is no way to turn it off (OPTS UTF8 ON) client command sending as far as i know.
So the client receiving output from a server that there is no such command inside the server.



Server's output:

Raw server output wrote:ftpdmin v. 0.96 Jun 7 2004
Using 'C:\' as root directory
ftpdmin ready to accept connections on ftp://192.168.0.105
220 Minftpd ready
OPTS UTF8 ON
Unknown command 'OPTS'
500 command not recognized

USER Administrator
331 pretend login accepted
PASS Password
230 fake user logged in
PORT 127,0,0,1,248,181
200 PORT command successful
NLST
150 Opening connection
226 Transfer Complete
QUIT
221 goodbye
Closing control connection


Client script used:

Code: Select all

@echo off 
set "REMOTE_SERVER=localhost"
(echo Administrator
    echo Password
       echo ls) | ftp %REMOTE_SERVER% | findstr /i /v "user"
pause


Client output:
Raw client output wrote:command not recognized
$Recycle.Bin
AMD
bootmgr
BOOTNXT
Documents and Settings
hiberfil.sys
Logs
pagefile.sys
PerfLogs
Program Files
Program Files (x86)
ProgramData
Recovery
swapfile.sys
System Volume Information
Windows
Windows.old
Press any key to continue . . .


Is it possible to prevent it using findstr also?
It is not really necessary cause any modern ftp server mostly able to handle OPTS UTF8 ON, i tested on one of them. So i guess it's okey.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Nulling output echo'ed from FTP SERVER while authenticating.

#9 Post by foxidrive » 09 May 2016 18:20

If the 'command not recognized' is what you would like to remove then filtering the word 'recognized' will remove that line - and any other line that contains 'recognized'.

Better filtering is possible but it depends if you have lines that contain user and recognized.

Code: Select all

  echo ls) | ftp %REMOTE_SERVER% |findstr /i /v "user recognized"


Judging purely from your description, OPTS UTF8 ON must be a command built into FTP.EXE

Post Reply