Solved

FTP Upload newest file using batch file?

Posted on 2011-03-21
6
875 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
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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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