Solved

FTP Command

Posted on 2014-02-14
8
427 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
  • 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
 
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
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 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now