This question already has answers here:
psftp.exe get files from the server and delete
(3 answers)
Closed 4 years ago.
I was wondering if someone knows how to do what I'm looking to do.
For my server, I download files from an FTP server daily at 5AM. My batch script is pretty simple, it connects to the FTP server, downloads the files, processes them locally, and then deletes the processed files from the local directory, but I am unable to figure out how to get the batch file to purge only the downloaded files from the server.
Here is the code I'm currently using (edited for privacy)
C:
cd "C:\targetfolder"
rem psftp -b download.cmd -i priv(second).ppk -P 2223 xxx#yyy.ca
psftp -b download(second).cmd -i priv(second).ppk -P 2223 xxx#yyy.ca
rem psftp -b download.cmd -i priv.ppk xxx#yyy.ca
psftp -b download.cmd -i priv.ppk -P 2223 xxx#yyy.ca
rename *.xxx *.xxx
del done*.*
So the script as it is successfully is run every morning and downloads my new files. Are there some line(s) of code I'm missing that will simply delete the downloaded files only?
I also want to mention that I cannot install any new software on my FTP server to manage the files, so it has to be processed in my batch code here.
Thank you in advance for any help you all may be able to provide!
EDIT1: Here is the script in the doanload.cmd
ls
cd target
ls
mget *
Solved, thanks to #MartinPrikryl.
I added "rm *" to the end of my cmd file and it's working nicely, even though it doesn't differentiate from downloaded and non-downloaded files, it does what I need.
Thanks #MartinPrikryl!
Related
This question already has answers here:
Pass commands as input to another command (su, ssh, sh, etc)
(3 answers)
Closed 1 year ago.
This is my batch script. I wanted to automate restart of the mysql
cd G:\My Drive\TCL
G:
ssh -i themedcreations.pem ec2-user#ec2-3-16-127-158.us-east-2.compute.amazonaws.com
sudo su
service mysqld restart
Pause
The script is okay if I manually input the lines in cmd.
I was hoping the batch file could run itself till the end, but it stops after running the ssh -i line, afterwards it requires manual input.
What went wrong? I am completely new to batch scripting. I tried timeout or wait. They all didn't work.
Use the -n flag and see if it solves your problem.
example
ssh -n -i themedcreations.pem ec2-user#ec2-3-16-127-158.us-east-2.compute.amazonaws.com
This question already has answers here:
How to ftp with a batch file?
(10 answers)
Closed 4 years ago.
I am trying to create a script which copies the contents of one directory to an FTP location but every example I have tried to work with has failed. I need this to target a folder within the FTP site can anyone point me in the right direction.
Thank you
Batch file is below.
#ftp -i -s:"%~f0"&GOTO:EOF
open 0.0.0.0
name#address.com
Pa55word
!:--- FTP commands below here ---
lcd c:\program files\system\location
cd storage
binary
mput "*.*"
disconnect
bye
Once FTP is open you are no longer at a command prompt. You are inside FTP. You need to use your batch file to write the ftp script,FTPInstructions.ftp in the following example. Then open ftp, telling it to run the script.
When you invoke the ftp.exe program to run the ftp script from the batch file you can redirect the ftp.exe console output to a log file and examine that log file for errors. You'll need to redirect both stdout and stderr. Something like this:
echo open 0.0.0.0>FTPInstructions.ftp
echo user UserName>>FTPInstructions.ftp
echo Password>>FTPInstructions.ftp
echo something>>FTPInstructions.ftp
echo something else>>FTPInstructions.ftp
.
.
echo bye>>FTPInstructions.ftp
ftp.exe -n -s:FTPInstructions.ftp>FTPSession.log 2>&1
You can then use FIND or FINDSTR in the batch file to locate any error messages output by ftp.exe in the FTPSession.log file.
This question already has answers here:
I can't upload a multiple files to FTP by batch script
(3 answers)
Closed 4 years ago.
I try to copy a lot of files from my ftp server ftp://ftp.prodega.ch, so I created a file called code.txt with this text:
open ftp.prodega.ch
user
password
lcd E:\f2
cd Bilder1
get file1.jpg
bye
Then I execute the following command in the command prompt:
ftp -s:code.txt
The file file1.jpg is copying into local E:\f2 folder; I try to copy all files from the ftp folder Bilder1 using mget * instead of get file1.jpg but it doesn't work.
The first image is copied successfully, but the second image (using mget *) doesn't get copied and showed this result:
How would I be able to copy these files?
Try entering this command into your command prompt:
ftp -i -s:code.txt
I am not able to run my batch file which is located on Share Drive..However it runs perfectly when the location is Desktop or local drive
Batch File Code:
cd "\\\172.17.23.42\Extra\"
"SL - EOD.acsauto"
Firstly, you must download the PsExec.exe tools from this link:
https://technet.microsoft.com/fr-fr/sysinternals/bb897553.aspx
Then, you type this command:
PsExec.exe -h -s \\NameOrIpOfYourServer -c -v PathFile_In_your_pc\file.bat
Best Regards
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