Filezilla not allowing connections by batch code via FTP connection - batch-file

I have a bit of code that will send some info to my FileZilla FTP server that is running on a PC of mine. When I enter the password I want and place it in the login spot in my code and run it. It keeps saying it is a Incorrect password and failing even when I KNOW that the password in there is correct. Someone have an answer?
1 I have tried to change the password many times and even simple ones like 123 and it still did not say it was correct |
2 I changed the security on the server many time as well and to nothing in return |
3 I have reinstalled Filezilla many times |
4 I changed firewall settings |
REM Setup the FTP folder
echo reverseCMD > a.dat
echo *********** >> a.dat
echo binary >> a.dat
echo mkdir %username% >> a.dat
echo cd %username% >> a.dat
echo put Info.txt >> a.dat
echo disconnect >> a.dat
echo bye >> a.dat
*** Removing IP's and passwords

Are you aware of the fact that all lines of your batch file output with echo are written with a trailing space into file a.dat because of space left to redirection operators > and >>?
See the answer on Why does ECHO command print some extra trailing space into the file? for details about how a command line with echo and a redirection operator is processed by cmd.exe.
I suggest the following code:
#echo off
REM Setup the FTP folder
(
echo reverseCMD
echo ***********
echo binary
echo mkdir %username%
echo cd %username%
echo put Info.txt
echo disconnect
echo bye
) > a.dat
And make sure the batch file does not contain trailing spaces/tabs on the lines with echo.

Related

In a batch file how to write to a file and see also what is going on with a ping test?

I have a big batch file with PING and Iperf tests and it works, everything is written in a .txt file, I only want to see what is going on in the PING test for example, apparently >> command only writes to the text file. My solution is to send one time the PING without the >> to write to the file and another one with the >> to write to the file but this takes a lot of time for the purpose of the batch file.
Can anyone help me with a simpler solution?
thanks
here is part of the code:
ECHO.
(
ECHO Test started on %DATE% %TIME%
C:\Windows\System32\ping.exe %SERVER% | findstr /r /c:"[0-9] *ms"
if %errorlevel% == 0 (
echo.
echo TEST de PING OK ! next test iPERF
) else (
echo TEST de PING NOK
ECHO Done
PAUSE
EXIT
)
) >> "%LOGFILE%.client.log"
There is a special device con, which is essentially your command line window.
(
echo this goes to file
>con echo this goes to screen explicitely
echo this goes to file too
)>file.log

How to avoid writing trailing spaces into text file on redirecting ECHO outputs to a file?

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?
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

Windows batch Script to select week number when calling a file

I have considered to incorporate a batch file in my SSIS package to put a file into an SFTP site via winscp.com and therefore need to write a batch file at the end which can put the needed file into a SFTP site, for which I have written the process below but I need help to call the file which looks like Filename_Week #(eg. Filename_1,file name_2...Filename_34) and is located M:\Test\DATA OUT folder. My feeling is to add an if statement (i.e. if [%v_week%] == [] SET v_week= week #) after set v_week=%1, but I am not sure what that would be since I have never written a batch file before.
SET v_week=%1
echo option batch continue > SFTP_Filename_Put.txt
echo option confirm off >> SFTP_Filename_Put.txt
echo open target >> SFTP_Filename_Put.txt
echo lcd "M:\Test\DATA OUT" >> SFTP_Filename_Put.txt
echo cd / >> SFTP_Filename_Put.txt
echo put "M:\Test\DATA OUT\Filename_%v_week%.txt" /Filename_%v_week%.txt >> SFTP_Filename_Put.txt
echo exit >> SFTP_Filename_Put.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\SFTP_Filename_Put.txt"
del SFTP_Filename_Put.txt
Like this it will automatically get the last created .fyi file and get the last 2 chars
and set your V_week variable.
#echo off&cls
setlocal EnableDelayedExpansion
for %%a in (*.fyi) do set $WeekNb=%%~na
set $WeekNb=%$WeekNb:~-2%
set v_week=%$WeekNB%
echo The Week Number Is : %v_week%
pause

How to Quit FTP in a script?

I'm attempting to write a .bat file for a simple password reset prompt for users, and the last thing I need to do is to quit, which is not being executed for some reason. The process halts after the connection is made, the quit command is ignored, and has to be typed in manually before the process resumes.
Here is what I have:
#echo off
Echo Password Reset Process
Pause
Echo Enter your user ID when asked
Echo ---
Echo Change your password by using this format, including the slashes:
Echo 'oldpassword/newpassword/newpassword'
Echo ---
Echo You will not be able to see what you type
Echo So proceed carefully!
Echo ---
Echo Begin Your Password Reset Now?
Pause
FTP Server.domain.org
Quit
Pause
exit
Thank you!
Try this:
#echo off
Echo Password Reset Process
set /P "userID=Enter your user ID: "
Echo Enter your new password by using this format, including the slashes:
set /P "password=oldpassword/newpassword/newpassword: "
Echo Begin Your Password Reset Now?
Pause
(
echo %userID%
echo %password%
echo Quit
) > passfile.txt
FTP -s:passfile.txt Server.domain.org
del passfile.txt
exit
Batch files only contain commands for the Windows shell cmd.exe. If you want to input commands into some other program, you have to use its means to do so.
With FTP, you can use the -s:filename switch, see ftp -h. So you can create a file, say ftp-cmd.txt, with the necessary lines and end it with the line quit and then in your batch file call ftp -s:ftp-cmd.txt. That should do the trick.

Batch Program Problem

I am currently trying to program a batch script which allows the user to enter the name of a website, and then writes "127.0.0.1 www.website.com" at the bottom of the user's hosts file (essentially blocking that website)
Everything is working except for one line. I need to write the following line into another batch file which will be created by my program:
echo find /v "%url%" < C:\WINDOWS\System32\drivers\etc\hosts > C:\Users\%username%\desktop\temp.txt >> unblock.bat
This line is part of the code which will be able to remove the website from the hosts file if the user wishes to.
The problem appears to be the "<" and ">" signs. The program will not allow me to write these to the new batch file. I have tried to save them as variables and realized that the only way i could do it was by declaring them with inverted commas like this:
set char1="<"
set char2=">"
and then my command looks like this:
echo find /v "%url%" %char1% C:\WINDOWS\System32\drivers\etc\hosts %char2% C:\Users\%username%\desktop\temp.txt >> unblock.bat
The problem with this is that when writing to the new batch file, they both still have "" around them which makes the new batch file useless as the command does not execute properly.
Any ideas on how to fix this?
Here's the whole code for the batch file (incomplete):
#echo off
TITLE Site Blocker
SET /P url=Enter website (e.g. www.facebook.com)-
echo. >> C:\WINDOWS\System32\drivers\etc\hosts
echo 127.0.0.1 %url% >> C:\WINDOWS\System32\drivers\etc\hosts
echo find /v "%url%" < C:\WINDOWS\System32\drivers\etc\hosts > C:\Users\%username%\desktop\temp.txt >> unblock.bat
echo del C:\WINDOWS\System32\drivers\etc\hosts /Q >> unblock.bat
echo ren C:\Users\%username%\desktop\temp.txt hosts >> unblock.bat
echo copy C:\Users\%username%\desktop\hosts C:\WINDOWS\System32\drivers\etc\ >> unblock.bat
echo del C:\Users\%username%\desktop\hosts /Q >> unblock.bat
echo msg * %url% unblocked >> unblock.bat
echo del unblock.bat >> unblock.bat
echo exit >> unblock.bat
exit
Escape the greater than and less than with a caret (^)

Resources