1

I have this code:

@echo off
color 0a
title FTP
CLS
echo username > FTP.txt
echo password >> FTP.txt
ftp -s:FTP.txt ftp.website.com

But I have the problem that it shows an error in authentication on execution because a space is appended on username and password in text file. It other words first line of FTP.txt is "username " and not "username". Also second line is "password " and not "password".

How to delete those spaces at end of each line or avoid writing them into the file?

Mofi
  • 46,139
  • 17
  • 80
  • 143
M. Wood
  • 21
  • 1
  • 5
  • 2
    of course there is a space, if you explicitely write a space. Instead of `echo username > FTP.txt` write `echo username>FTP.txt`. Same with Password. – Stephan Dec 10 '15 at 19:28
  • 2
    If that seems awkward to you, you can also put the redirection at the beginning of the line and achieve the same effect. `>FTP.txt echo username` and `>>FTP.txt echo password`. The difference is purely cosmetic. Or you can `>FTP.txt ( command 1` `command 2 )` – rojo Dec 10 '15 at 19:31

1 Answers1

3

As Stephan comments above, the space after username and password is being treated as a literal space, not a token separator. Remove the spaces before the > redirectors.

echo username>FTP.txt
echo password>>FTP.txt

If that seems awkward to you, you can also put the redirection at the beginning of the line and achieve the same effect.

>FTP.txt echo username
>>FTP.txt echo password

The difference is purely cosmetic. Or you can open FTP.txt only once for writing, but use multiple statements to write before closing. This is actually a bit more efficient.

>FTP.txt (
    echo username
    echo password
)

or

(
    echo username
    echo password
) >FTP.txt
rojo
  • 24,000
  • 5
  • 55
  • 101