Solved

FTP Command

Posted on 2014-02-14
8
434 Views
Last Modified: 2014-02-14
Hello All

Is it possible to use the FTP command mget to download files from a Windows Server and then delete them off the server, or move them to another directory?

Cheers
V.
0
Comment
Question by:vision_on
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39858591
What are you trying to do, i.e. do you know which files etc?

You could do this in a couple of ways, e.g. download the files and keep a note of which ones you successfully retrieve then start a new session and delete / move the files.

What are you using so far, something like one of these:
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39858599
You might be able to use rename in the ftp command to do rename "x.y" "subdir\x.y" say

Steve
0
 
LVL 1

Author Comment

by:vision_on
ID: 39858610
Hello Steve

Yes I could use rename if I knew what the files names were , however I need to use wildcards to mget the files:

mget *.csv
mget *.txt

If there is a way I could use rename with wildcards that would sort out the issue....?

Cheers
V.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39858649
It depends upon the server.  I would say best to collect the files locally into a subdir, e.g.
roughly something like this then you would only delete the file having successfully downloaded it too:

@echo off
set localdir=c:\mydir
set remotedir=/remotedir
set ftpserver=x.x.x.x

del "%localdir%\*.*" /q

call :GetFtpFiles
call :ClearFTPFiles

exit /b

:GetFTPFiles

(echo open ftpserver
echo user username
echo password
echo bin
echo prompt 
echo cd %remotedir%
echo lcd "%localdir%"
echo mget *.csv
echo mget *.txt
echo quit
) | ftp -n -i



exit /b

:ClearfTPFiles

(echo open ftpserver
echo user username
echo password
echo prompt 
echo cd %remotedir%
for /f "tokens=*" %%a in ('dir /b /a-d "%localdir%\*.*"') do echo DELE "%%~a"
echo quit
) | ftp -n -i


exit /b

Open in new window

0
 
LVL 1

Author Comment

by:vision_on
ID: 39858681
Excellent that should do the trick, thanks!
0
 
LVL 16

Expert Comment

by:AlexPace
ID: 39859317
@Steve - How does this script ensure the files were downloaded successfully before it deletes them?  What if the connection dropped during the download or if the files could be transfer but not written to the local machine because of a permissions issue?  Would they still be deleted anyway?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39859437
It doesn't necessarily.  But then doing an "MGET" followed by DELE *.* wouldn't either.

It depends upon the situation, how important and critical the files are etc.

Steve
0
 
LVL 16

Expert Comment

by:AlexPace
ID: 39860650
OK, thanks!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question