Solved

FTP Command

Posted on 2014-02-14
8
433 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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 is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
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 …
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.

730 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