Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

window - delete a file from local drive after successful upload to ftp using batch file

i want to delete file from my local system after successful send to ftp using batch file. for scheduling purpose i m using window scheduler. below is my code which is able to post to ftp.how to delete that successful send to ftp otherwise file shld not delete.

 %windir%system32ftp.exe -s:%~f0
 goto done
 cd C:
 open Host Name
 user_name
 password
 bi
 put user_input.csv
 bye
 :done
 @echo off
 cls
 exit 

if i will write delete here then it ll delete from remote server.pls suggest me how to do that using window ftp.exe

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to redirect the output of the FTP command. Check for a succesful message and act upon it.

I can't provide an exact script, because it will depend on the FTP command you actually use, but the idea is like this.

echo open Host Name >%temp%ftpin.txt
echo user_name >>%temp%ftpin.txt
echo password >>%temp%ftpin.txt
echo put user_input.csv >>%temp%ftpin.txt
echo bye  >>%temp%ftpin.txt
ftp -n -s:%temp%ftpin.txt >%temp%ftpout.txt
for /f "tokens=* skip=9" %%a in (ftpout.txt) do (
   if "%%a"=="226 Transfer complete." (
   del user_input.csv
   )
)

EDIT: You will have to adjust your BAT to the actual output of your FTP script. Probably you will need to change the "skip" parameter of the FOR command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...