Archive for August 9, 2012

Command-line Passive FTP – Dreaded 150 Opening ASCII mode data connection.

I hope I can save someone some time with this.  I had to create some simple batch scripts to move some files around to different servers in geographical locations, fair enough.  I configured two without issue, but then my script ran into a problem, it would hang on the ‘ls’ command when testing at 150 Opening ASCII mode data connection.

It all boiled down to the inability for the default FTP command-line program to connect passively to an FTP server.  I could connect fine using Windows Explorer, which has passive mode enabled within IE and also via WinSCP with passive enabled also.  The annoying thing was that I had complete control over the FTP servers I was connecting to, so I went about trying to troubleshoot the server rather than the client side….!

After finally figuring this out, I went in search of a command-line solution, and found one in the form of NCFTP(http://www.ncftp.com/ncftp/) of which I just needed NCFTPPut (http://www.ncftp.com/ncftp/doc/ncftpput.html) of which I just downloaded the pre-complied Windows binaries and grabbed out NCFTPPut.exe from its installation destination to where I needed it in my batch script, yes I could have just left it there but didn’t.  And a couple of simple commands later, Passive FTP via the command line for use in a batch script! Example of the syntax I used below:

ncftpput.exe -u username-p password ftpserveraddress destinationfolder sourcefolder

As easy as that… 🙂 I hope it saves someone else hours of troubleshooting.