Solved

FTP Upload newest file using batch file?

Posted on 2011-03-21
6
874 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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