Solved

FTP Command

Posted on 2014-02-14
8
422 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

760 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

18 Experts available now in Live!

Get 1:1 Help Now