How to delete local computer files in the ftp session with a file. scr? - session

I have a .bat file (test.bat) :
ftp -s:Test_DOWN.scr
pause
I have a .scr file (Test_DOWN.scr) :
open ftp01.citobi.be
USERNAME
PASSWORD
prompt n
mput *.csv
quit
cd C:\...
del *.csv
The problem is that I want to remove files in my directory C:... but when I execute test.bat, it doesn't execute the last two lines.
I want to know if it is possible to run these two lines in the same script after ftp commands?
ps : When I launch prompt command from start --> run --> cmd and I connect to ftp. The quit ftp command works well, I pass the ftp session to host session. But with the .bat file, after quitcommand, it's over..

I solved the problem...
I used ! ftp command (escape to the shell).
!del *.csv
And it works well.

Related

How to execute further batch file commands after running "ftp" commands contains in the batch file itself

I have a .bat document where I do some operations with FTP. I want to end the FTP connection and get to finish with the terminal on the desired directory.
I'm trying this, but when it gets to quit, it stops.
cd %USERPROFILE%\Foilder\project\angular
call ng build
#FTP -i -s:"%~f0"&GOTO:EOF
open connection
user
password
cd httpdocs/project
mdelete *.woff
quit
cd %USERPROFILE%\Foilder\Subfolder
It gives me this message right after doing the quit and never runs the next line.
221 Goodbye.
Ideal scenario, run this last cd command and have the terminal ready on the folder that I want to run it. Thing is that I have to do some uploads to two different FTP servers and it would be great to have the console finishing in the folder where I run "dev.bat" to get it to work
Is it possible to do this?
Your script uses a known hack that allows you to specify ftp commands directly in the batch file.
The %~f0 is replaced with the path to the batch file itself. So the ftp -s:%~f0 runs ftp and tells it to use the batch file itself as ftp script file. You have probably noticed that it results in couple of errors, as ftp fails on the first few lines of the batch file, which are not valid ftp commands (the cd ..., call ... and ftp ...).
Equivalently, the batch file would try to run all commands after ftp ... once ftp finishes, also failing, as those are not valid batch file commands. To avoid that, the hack uses GOTO:EOF to skip the rest of the batch file (EOF=eof of the file).
While you actually want to execute some commands after the ftp. At least the cd command. So do not skip the rest of the batch file. Skip only the ftp commands:
ftp -i -s:"%~f0"&goto AFTER_FTP
(ftp commands)
quit
:AFTER_FTP
cd %USERPROFILE%\Foilder\Subfolder
Note the # before ftp. That (and the GOTO:EOF) are clear signs, that the script you based your batch file on, was designed to start with ftp on the very first line and contain nothing else, but the ftp commands. You have deviated from that.
Alternatively, use some more capable FTP client that allows specifying the commands on its command-line without hacks.
For example with my WinSCP FTP client, you can do:
cd %USERPROFILE%\Foilder\project\angular
call ng build
winscp.com /ini=nul /command ^
"open ftp://user:password#connection/" ^
"cd httpdocs/project" ^
"rm *.woff" ^
"exit"
cd %USERPROFILE%\Foilder\Subfolder
There's a guide for converting Windows ftp script to WinSCP script.

mget in batch script does not work

i'd like to create a batch script which logs on a ftp-server and copies some files to a remote folder. but my script does not work. mget runs into a timeout (has to be terminated manually).
i'm starting ftp connection with ftp.bat:
ftp.exe -s:getdata.bat
getdata.bat:
OPEN host-ip
user
password
lcd "C:\tmp"
cd config
mget C1000.xml
close
starting, logging in and changing the directory works but getting the file doesn't work. nothing happens until i end the script manually. any hints?
regards,
michael
mget prompts for user confirmation for each file it finds, even when you only specify one specific file.
To get around this, you can either use get if you know the file name, or you can use prompt to disable the interactive prompt before you use mget.
OPEN host-ip
user
password
lcd "C:\tmp"
cd config
prompt
mget C1000.xml
close

cmd upload (windows server 2012)

I have command in ftp.txt
open ftp.web.cz
jmeno
heslo
prompt
mput C:\upload\*
quit
This command call in ftp. bat (ftp -s:C:\ftp.txt ), but show error - Error opening local file.Can I help me? Thank you
Use lcd to change local working directory and cd to change remote working directory. Consider whether specify ascii and / or binary transfer type.
open ftp.web.cz
jmeno
heslo
prompt
[cd "/destinationfolder"]
lcd "C:\upload"
mput *.*
quit

Batch file doesn't execute specified .exe on remote computer

I am trying to install a program on a remote computer using a command line argument and a batch script. For testing, I'm installing Notepad++ as the program.
Here is the command line I'm using to access the remote computer:
psexec \\comp-2 -h -u localAdmin -p password -c -f C:\install-npp.bat
This is the batch file code I've written:
#echo off
#echo Hello this creates a pointless temp file >C:\temp\EmptyFile.txt
xcopy \\FILESVR\Shared\npp.exe C:\temp\npp.exe
start C:\temp\npp.exe
pause
(Please note: the second line is only to make sure that the script is in fact doing something).
When I run the psexec command listed above from my first computer, the EmptyFile.txt is created, and npp.exe is copied over to the temp directory, but the executable is never run.
What am i doing wrong? the machines are in a windows workgroup.
Thanks in advance!
the start command is waiting a title as first argument so try start "" c:\temp\npp.exe.
BTW looking at http://coreworx.blogspot.fr/2010/07/unattended-installation-notepad.html I saw you will have to add /S to make a silent install of npp

Check existence of directory on local machine during ftp session

I am copying a large number of files during an ftp session from a remote host to my local machine. I need to save the files in a local directory tree. My problem is that a particular directory may not exist before the session. The way I have handled this in the past is to do set up my script by first creating the directory tree and not even worrying if the directory exists and then from within the same batch file (I create the batch file using Python) I start my session and use lcd to change to the correct directory
md c:\123
md c:\234
md c:\234\2009
loginname
password
cd remotedirectory
lcd c:\123
get somefile.txt
So all of the above is written out to one batch file and I start it to run. If the directory exists when I try to create it then I see a message in the terminal window that the directory exists and since nothing bad happens I have not worried about it.
What I would really like to do is check the existence of the local directory when I am ready to move to that directory and if it does not exist it gets created but I have not found out how to do this without closing the session and restarting it so I go back to the shell.
Is there a way to do this during the ftp session while maintaining the connection with the host?
You can use the ! command prefix to execute CMD MD command in order to make sure a local directory is already exist. e.g.:
! md "c:\my data\download" will create c:\data\download directory if it's not yet exist (and assuming you have the required permission). If it's already exist, it'll just display a harmless error. You can also use ! md "c:\my data\download" > nul to omit the error message. Or perform other commands.
Basically, everything after the ! ftp command prefix, will be passed to CMD.EXE as cmd /c {your command(s)}. If ! is used alone, it'll escape to CMD session prompt and wait for user input. The CMD's EXIT command will close the CMD session and return to the FTP prompt.

Resources