Solved

FTP Upload newest file using batch file?

Posted on 2011-03-21
6
871 Views
Last Modified: 2012-08-13
I am trying to create a batch file that would upload the newest file in a directory to an FTP folder.   So far I have this:

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in ('dir/b/a-d/od') do (set latest=%%a)

> #.ftp echo o 10.1.2.229
>> #.ftp echo anonymous
>> #.ftp echo lims@domain.com
>> #.ftp echo cd /DATALOG/CDAT/
>> #.ftp echo bin
>> #.ftp echo put !latest!
>> #.ftp echo bye

ftp -s:#.ftp

However, it seems to stop at "150 Opening BINARY mode data connection", and doesn't transfer the file.

What am I doing wrong?
0
Comment
Question by:larry
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35182207
Can you do the same commands manually from an ftp.exe prompt?  Perhaps you need to put it into PASV mode, or the PUT command is not coming out right in the #.ftp file, perhaps needing " " around a file with spaces etc?

Steve
0
 

Author Comment

by:larry
ID: 35182920
Thanks for the reply.  I seem to be having a problem with my FTP connection.  When I manually try to upload a file, I get the message:

200 PORT Command successful.
150 Opening BINARY mode data connection.

And then it just sits there until I abort the connection.

That was on the Windows 7 machine.  I did try it on a different workstation and it worked, so I'm not sure why it's not working on the Win7 box.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 35183840
try adding
PASV

as a matter of interest, or maybe turn off the firewall temporarily?

Steve
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 16

Expert Comment

by:AlexPace
ID: 35184568
1. Copy the script code below into a new file named "send_newest.s"
;; enable logging
LOG "send_newest.log"
TRACELOG "send_newest.trace.log"

;; set local source folder
WORKINGDIR "c:\source\folder\path"

;; find newest file in source folder
GETFILE "*" /newest
IFERROR!= $ERROR_SUCCESS GOTO done

;; connect to FTP server and upload file
FTPLOGON "10.1.2.229" /user=anonymous /pw=lims@domain.com
FTPCD "/DATALOG/CDAT/"
SENDFILE %nextfile

:done
FTPLOGOFF
EXIT

Open in new window

2. change the WORKINGDIR line to match the path of your source folder.  
3. Download and Install the 30-day trial of Robo-FTP
3. Use Robo-FTP to execute the script file
4. If the file transfer fails open the log named send_newest.trace.log under the Robo-FTP installation folder.  You can view the log in notepad.  It will show what is happening on the protocol level so you can tell if perhaps the data channel is blocked.  If you can't figure it out from the log you can post the trace log here and we'll help.
0
 

Author Closing Comment

by:larry
ID: 35184730
It was a firewall issue, thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35185527
No problem, firewalls can be a pain with FTP!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

705 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

19 Experts available now in Live!

Get 1:1 Help Now