I think the issue was by ths following , As Matt Williamson said, adding the command open host with the port open 172.xx.xx.xx 22 > ftpcmd.dat to the was the solution, dont know why it cant read the address directly from the script. Here is the working ftp part of the script:
SET ftphost=172.xxx.xxx.xx 22
ECHO open %ftphost% > ftpcmd.dat
ECHO user %username%>> ftpcmd.dat
ECHO %userpass%>> ftpcmd.dat
ECHO bin>> ftpcmd.dat
ECHO put %file%>> ftpcmd.dat
ECHO quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat
When should an FTP server connect to FTP client after PORT command?
wish helps you The server shouldn't connect to the client until it gets a command that requests a data transfer, such as LIST or RETR. See section 7 of RFC 959, which shows a typical sequence of operations (RFC's didn't have the formal MUST/MAY/SHOULD specifications in those early days). However, since the port used in the PORT command is typically an ephemeral port, the client needs to open a socket to get the OS to assign a port number. This implies that by the time the PORT command is sent, the port would have to be open. However, it's possible that it might not yet have called listen().
How to connect to a server without the port number in java?