deleting multiple files From FTP - batch-file

Is there any way to delete all files From FTP. i'm able to delete single files,but not able to delete all the files.I've tried below script but not working for multiple files.
ftp
open <SERVER>
<Usename>
<Pass>
cd </file_location>
delete *.xlsx`
bye
"It's showing Error,No such(*.xls files)".
If I use delete File_Name then it's working.I've also tried mdelete and rm. Please help me how can i delete all the files with .xlsx extension.

mdelete would have worked if you disabled prompting first.
ftp
open <SERVER>
<Usename>
<Pass>
cd </file_location>
prompt
mdel *.xlsx
bye

Related

Windows Batch script to SFTP files to remote location and then move them up a directory once finished

I have an issue where the files I am uploading to a vendor are being consumed before they are finished uploading. To get around it the vendor has provided me with a location underneath where I can upload the files first then requested I move them once the upload is done.
Stripping out sensitive information, I am referencing this file in my sftp command in batch myfile.scr
cd /from_client/payments/upload
lcd E:/uploadfiles
mput uploadfiles.xml.*
quit
That would upload the files to the remote directory upload. I know need to get them into the level above. The theory is this will then process as normal and the files will already exist so the application won't consume them before they are done uploading.
I would assume I need to do a job to build a list of the files and then a 2nd to loop through them to do a rename on the remote folder to get them to go up a level.
Any ideas on how this could work? The vendor is unable to do anything here.
already tried various solutions to see if I could use mv but thats not an option as its not using Winscp. We can only use batch scripts and then native sftp commands.
You can generate put and rename commands for each file using a batch file like this:
set SOURCE=E:\uploadfiles
set SCRIPT=myfile.scr
(
echo cd /from_client/payments/upload
echo lcd %SOURCE%
for %%F in (%SOURCE%\*) do (
echo put %%~nF
echo rename %%~nF /final/path/%%~nF
)
echo quit
) > %SCRIPT%
sftp user#host -b %SCRIPT%
It should generate a script like this:
cd /from_client/payments/upload
lcd E:\uploadfiles
put one.txt
rename one.txt /final/path/one.txt
put two.txt
rename two.txt /final/path/two.txt
put three.txt
rename three.txt /final/path/three.txt
quit
Though with a more capable client, it would be easier. For example my WinSCP supports wildcards with mv command, so you can simply do:
WinSCP.com /ini=nul /log=winscp.log /command ^
"open sftp://user:password#host/ -hostkey=""...""" ^
"put E:\uploadfiles\* /from_client/payments/upload/" ^
"mv /from_client/payments/upload/* /final/path/" ^
"exit"
I'm aware that you wrote that you cannot use other clients, because:
"It's not using WinSCP" – What "it"? It's you! Use the best tool for your task.
"We can only use ... native sftp commands" – There are no "native sftp commands". There are only commands of the client you are using. Currently you are using OpenSSH sftp client. But that's not set in stone. It's easy to switch (you do not even to read it, everything is already in my code above).

FTP command "get *.txt" error "550 File not Found"

My problem appears when I try to download files with a batch file over the FTP.
OPEN 192.168.0.1
test
password
lcd Download-dir
cd /filedir
BINARY
get *.txt
Everything works well up to the moment he try to find the File. At that moment he call the
Error 550 File not Found.
When I try the same with
get Test.txt
It will work fine.
Every tutorial use the * as wildcard but why does it not work for me.
Thanks for help.
The get command in ftp.exe does not support wildcards.
You have to use the mget command:
mget *.txt

Batch file and ftp script works, unless used with task scheduler

I have written a batch file that calls an FTP script that downloads files from multiple folders from a remote server. When I execute the batch file it works perfectly. However when I schedule it with task scheduler it pulls all the files down except for those in one specific folder.
I've checked permissions, there are no issues there. The relevant parts of the batch file and FTP script are below. For the purposes of this question I've shortened both. So the question would be why does it download from the "RWSmith" directory but not the "TrimarkFoodcraft" directory when run from Task Scheduler. I know that batch files are not case sensitive but I added the extra suffixes because the files do end in .DAT instead of .dat and they were not downloading.
Script and Batch File are on Windows Server 2008 R2 and the server it is downloading from is Windows Server 2003.
Batch File:
ftp -i -s:ftpCommands.txt 0.0.0.0
FTP Script:
username
password
cd "AdamsBurch"</br>
lcd "C:\EDIScanner\DistributerEDIFiles\AdamsBurch"
mget *.dat
mdelete *.dat
cd \
cd "RWSmith"
lcd \
lcd "C:\EDIScanner\DistributerEDIFiles\RWSmith"
mget *.dat
mdelete *.dat
cd \
cd "TrimarkFoodcraft"
lcd \
lcd "C:\EDIScanner\DistributerEDIFiles\TrimarkFoodcraft"
mget *.dat
mget *.DAT
mdelete *.dat
mdelete *.DAT
close
bye
The FTP account might not be in the root directory. After connecting, use pwd to see what directory is current.
username
password
pwd
Instead of assuming the directories are off of the root, use relative references.
cd ..
cd "TrimarkFoodcraft"

mysqldump batch script runs but leaves empty file

I have made a simple batch script to back up a database, however when it runs it creates a empty file. This batch script is located in the same folder where mysqldump.exe is located. Following code:
#ECHO off
start /wait mysqldump.exe -u user -p "password" database > "Z:\sql-backup\"database-backup.sql
Any help would really help. New to Batch scripting.
I had used the below commands in batch file and it has worked properly.
First of all you should goto bin directory and issue the below mentioned mysqldump command. The same you can mention in the batch file as it is.
cd C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin
mysqldump -uroot -ppassword database > "C:\ProgramData\MySQL\MySQL Server 5.6\Data\"Database_bkp.sql

A batch file to download and delete files from a server

How can I write a MS dos ftp batch file to:
download files from the server to my local pc
remove these files from the server after download
Edit:
So far I have...
Batch file:
ftp.exe -s:ftp.txt
FTP.txt:
open domain.com
usernamehere
passwordhere
cd /httpdocs/store/files
need get, list and delete commands here??
quit
The ftp.exe program can take a sort of script file as input (that example uploads a file, but I guess to get the idea), so you should probably be able to create a script for the commands that you need to carry out, and then have a batch file launch ftp.exe with the appropriate input.
From one of my cuestions in other post.
user-name
user-password
lcd c:\localfolder-where-download
cd remote-folder
mget .
mdelete \\remote-folder\ .
quit
1 & 2 line , your credentials
3 - line local folder where the ftp can download the content
4- line - remote folder if needed
5- line - get al content to your local folder
6- line - delete all content from your remote folder
7- line quit!
you can download ncftpput/ncftpget. With ncftpget, there's option to remove remote files after downloading.

Resources