?
Solved

FTP Command

Posted on 2014-02-14
8
Medium Priority
?
438 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

752 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