FTP script not working

Hi,

I have one FTP script which simply sends the file to target server via netrc.it used to work as normal for years.recently target server IP got changed , same has been updated in .netrc but unable to connect it via FTP though netwrk guys already opened the port 21,20 and 22 .

NETRC

machine 10.255.23.157 login xxxxxx password yyyyyy
macdef imupload1
        cd /PROJECT_D/01_source_layer/01_raw_source_files/IFMSFUEL
        lcd $2
        prompt off
        ascii
        verbose on
        put $1
        quit

telnet output

telnet 10.255.23.157 21
Trying 10.225.4.23...
Connected to sasbi.mas.net.
Escape character is '^]'.
220 kjvjdw01 FTP server (Version 4.2 Mon Apr 28 09:58:37 CDT 2014) ready.

After executing the FTP script got below error

200 PORT command successful.
425      No data connection
quit
: A remote host did not respond within the timeout period.

anyone advise where the pointer went wrong.

I would tentatively suggest that this could be a firewall problem. With a plain FTP (or what you have here) you might be trying to use what is called an Active connection, so there is a controlling connection (to port 21) and the server opens a data connection between another random port (there is probably a rule for this somewhere)

If the firewall does not allow the data connection, then i think you get this type of error - but it might not be exclusively this type of error. If you can make the FTP a Passive connection (i.e. the data and control all flows across the initial connection to port 21) then it should be okay.

Have a read of these to see if they help:-

You might get away with just adding passive to you list of commands before you try to put the file.

I hope that this helps,
Robin

1 Like

This is how this would usually be configured.

The script would address the target host by name, e.g. jupiter

When ftp is called in a script:

ftp jupiter

the host name is looked up in /etc/hosts to produce the target ip address.
So the /etc/hosts entry for the target needs to be correct.

A .netrc record would then be:

machine jupiter login xxxxxx password yyyyyy

Also, for a .netrc to work at all.....

  1. .netrc MUST be in the home directory of the user under which the ftp script is running
  2. .netrc MUST be owned by that user.
  3. .netrc MUST have access rights 600 giving read/write only to that user.

I initially suggest you check all that out to ensure the editing for change of ip address hasn't screwed any of that up.

1 Like

I have added and tried issue still remain same as below

put abcd.DAT
local: abcd.DAT remote: abcd.DAT
227 Entering Passive Mode (10,225,4,23,182,12)
ftp: connect: Connection timed out
quit
221 Goodbye.

even cant dir or ls as well.

 ftp 10.251.29.30
Connected to 10.251.29.30
220 10.251.29.30 FTP server ready.
331 Password required for XXXX.
230 User XXXX logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (10,225,4,23,205,0)
ftp: connect: Connection timed out

I have verified all are in place.

note: to the same target machine have tried from another source machine and FTP works fine from there.

---------- Post updated 06-20-17 at 02:49 AM ---------- Previous update was 06-19-17 at 09:28 PM ----------

.................

What OS's are the client and server?

Has the network topology changed at all concurrent with the change of ip address?

I would be thinking that somewhere on the route the required payload is not allowed. Connecting the FTP session is achieved with quite small packets but as soon as you attempt to do anything else, the payload will radically increase. If devices have different maximum payloads configured then packets are denied, ie, lost. Timeout would result. I also wonder whether one device is trying to open a different port at that point which is denied.

I'm still thinking about this one. Strange!

---------- Post updated at 09:24 AM ---------- Previous update was at 09:20 AM ----------

Using PASV as suggested by rbatte1 is the most common resolution of such problems but the ports used in passive mode need to be open too.

Are you using the native ftp client and server implementations from your OS's? Or are you using a third party variant?

2 Likes

source and destination servers are linux.

Yes there are new network rules/policies in place but network guys have opened the port 21 already .

the one is working which is working it sits in the same DC where target machine is there.

but the questioned server unable to place the file is in different Data center.

Yes, but if you search the web for "ftp passive" mode you will see that, typically, another port is opened when passive is requested. It's often in the range 50000-51000 so network teams open that range too.

If you have tested from a third party host and it works okay, what happens if you try between that third party and the troublesome box? (I appreciate one of those has to act as a ftp server which isn't quite the same thing, however, if we think we have a network issue here, it would be an interesting test.)

2 Likes

They also have to open port 20 udp.

1 Like