Solved

FTP Upload newest file using batch file?

Posted on 2011-03-21
6
877 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
[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
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

622 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