You've successfully subscribed to Nuvotex Blog
Great! Next, complete checkout for full access to Nuvotex Blog
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Scripting: FTP Upload behind a firewall

WinSCP - a small tool to connect to a ftp server in passive mode.

Sebastian Augustin
Sebastian Augustin

A normal day of a Windows Sysadmin: You just want to upload some files with a small script to a ftp-server but the firewall in your site does not allow active ftp uploads. (Hint: The Windows build-in ftp.exe does only support active ftp connections.) So what to do?

Background: Active FTP vs Passive FTP

Active FTP

In active mode the client starts listening on a random free port. It informs the server on which port it is listening and is waiting for the connection. Normally the client is behind a firewall, so the incoming connection of the server will be blocked by default. In this situation you will not be able to connect with the ftp server and send your data.

Passive FTP

In the passive mode the client tries to connect to the server and receives a IP address and a port from the server, to which the client can connect to. So the client initiates the data connection and should normally be able to send data to the ftp server.
Exception: If there are outgoing restrictions in your firewall - passive ftp will also not work. So you have to contact your firewall administrator.

The Answer: WinSCP

WinSCP - it allows scripting and the passive FTP mode. So you can automate the upload of generated files via the Windows Task Scheduler.

How to execute the script with WinSCP: /script="PATH_to_SCRIPT"

Simple script to connect to a ftp server and upload some file:

option batch on
option confirm off
open ftp://user:password@host -passive=on
option transfer binary
put 'C:\PATH_to_FILE'

That's it. Small and simple.