Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FTP Upload newest file using batch file?

Posted on 2011-03-21
6
Medium Priority
?
878 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 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