batch file ftp authentication issue - batch-file

I'm trying to download some files using a batch file, however after reading the username line an error is thrown 'Invalid command'.
In my batch file I call my ftp file as follows:
ftp -n -s:ftp_download.txt
my ftp_download.txt looks like this:
open myname.com
test#myname.com
test
lcd C:\myDownloads
cd download_files
get MY_NEW_FILES_*.xml
bye
However after the test#myname.com line an error is thrown 'Invalid command' and thus the script does not connect to my ftp server.
When authenticating as follows:
open myname.com
user test#myname.com test
I get the 'not connected' error
However using this username (test#myname.com) and password (test) I'm still able to connect using Filezilla .
Am I missing a command somewhere?

To those, like CharlesKSQL, who might stumble upon my question.
Here's how I got it to work (it turned out I had to use sftp for some reason so make sure it's enabled on your server);
The script (ftp_download.txt) contains the following:
option batch abort
option confirm off
open sftp://<username>:<password>#<host> -hostkey="<fingerprint/key>"
option transfer binary
cd <your folder>
get <some file>
If you do not know the fingerprint and/or key; you can find these in FileZilla when connecting trough sftp. They are shown in the popup that show up when you connect to your server for the first time or you could click the little lock-icon in the statusbar on the bottom right when you are connected already.
Now to actually connect you'll need a little bit of software (when using Windows) to create the secure connection. I used WinSCP.
You can download the portable executables here and place them (for easy usage) in the same folder as your batch file.
Then you can call the executable in your batch file by adding a parameter:
winscp.exe /script=ftp_download.txt
which should then execute your download script.
P.S.: it's been a while since I finished this, it's still working as far as I know.

Your text file should look like this:
open myname.com
user
<enter username here> <password here>
lcd C:\myDownloads
cd download_files
get MY_NEW_FILES_*.xml
bye
Try that and see if it helps

Related

How to download only lines with specific ID from a file on SFTP server

I have created a bat file which runs WinSCP script to download a log file (response log) from remote server. The log file obviously downloads as-is (responses from all the requests). How can I limit the download of log file specific to my request? My request has a unique ID, how can I trim the response specific to my unique ID? TIA
Script within my bat file is as below:
winscp.com/command ^
"open sftp://xxx.com/ -hostkey=*" "get /var/log/jboss_sit/suFile.log" "exit" ^
It seems that you want to filter a text file to lines that contain a substring.
That's not possible with SFTP protocol. It does not allow filtering files.
You have to use other interface for that. For example, if you have a shell access, you can use grep command. You can execute shell commands like grep with WinSCP command call. Though if you do not need anything else, using a console terminal client might be more appropriate, than WinSCP.

Clear a log file that is still accessed by its program

I regularly clear a log file as I run some tests and I want to keep that log readable.
I have a batch file using the command below that works whenever the program that is being logged is turned off.
del /f *.log
When the program (a tomcat server) is running, I have an 'access is denied' error because the file is being used by another service.
I don't want to turn the tomcat off and on every time. My current workaround is to edit the log into notepad++, select all, delete, save and close notepad++.
Is there a more efficient way of doing that? I have a few batch to clean multiple times a day so I would like to automate.
Is it possible to create a .bat that would do that for me? I thought of exporting a notepad++ macro into a batch file but my various research were not successful.
I tried:
echo off
echo. > filename.log
but the result is the same => access is denied because the file is already in use.

FTP script Windows invalid command character appended?

I am trying to figure out what is wrong in my script. I am trying to automate the task of getting data from many FTP servers, using PowerShell as scripting environment.
I am using
ftp.exe -n -s:Script.txt $SOMEIp
It was giving me output:
Connected to 10.128.10.195.
220 Service ready
User(10.128.10.195:(none)):
530 Invalid user
Login failed.
I tried some troubleshooting by experiencing with the script and so on - the initial result is that
Is the "rectangle" char appending "a" character causing this or what is exactly wrong with the script?
In any case:
admin
password
cd ...
ascii
get somefile.txt
quit
is the script, while command to execute it, as I mentioned,
ftp.exe -n -s:Script.txt $SOMEIp
On the PNG file you see some troubleshooting file, where I tried to "ignore" the first wrong line and then restart with user and password prompt.
Would be great if you could share some ideas on that matter.
Cheers
Alex
Try saving your Script.txt as ASCII or ANSI. It could be that your ftp client doesn't understand unicode.
Try changing your script to this:
user admin password
cd ..
ascii
get somefile.txt
quit
You need to tell the FTP server that what is coming is the username and password. Also, you need two dots not three to go up a level.

How to overwrite file which is using by an application, with ftp commands

I need to distribute files over network to other servers (OS: Windows Server 2003) with below ftp script.(See attachment-1) I'm trying to overwrite some files which are currently used by an application. I should not stop the application while I doing this. When I try to use this script, I'm getting an error (See attachment-2) and the file did not overwrite.
Attachment-1
ftp_command.txt
username
password
lcd C:\deploy
bin
prompt
mput *.txt
disconnect
bye
runner_command.bat
ftp -s:/home/script/ftp_script.txt <IP Address>
Attachment-2
Error Message:
550 The requested operation cannot be performed on a file with a user-mapped section open.
There is no way around that with ftp. The file is in use--if it were to be replaced, the application that's using it would likely fail because it would not be aware of the change. You will have to find a way to stop the application that is using the file.

Updating SVN remotely via batch file

I tried searching relevant threads, it didn't worked. So here are the detailed question / situation, where I am looking for help.
I have 30 client nodes where I have setup SVN and checked out two folders (which needs to be updated) exactly when I want (forcefully).. e.g : "d:\gbv\textures" and "d:\gbv\characters"
then I put svnUpdate.bat file in main d: drive with relevant command e.g: "svn update blabla"
if I run this bat file by double clicking, it works fine ( it updates )
now I thought, I should create a batch file, where I type all 30 nodes IP, and set of commands, to run that batch file from local d: and it should work.
PROBLEM: I am unable to do this.
because I am unable to do this, from my cmd panel.
because I am not sure, how I can access network pc and tell it to run "d:\svnUpdate.bat" from its drive from dos prompt. ( obviously, I can do this via win explorer visually ).
Hopefully the question will make sense.
You can execute files on remote machines in a network using PsExec. I use it to execute batch files and pass parameters to them.
You'll probably need the -w option to set the working directory.
Of course this is a lot easier with powershell remoting, but since you already set it up with batch, PsExec works fine.

Resources