Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

FTP script not working

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-19-2017
Riverstone Riverstone is offline
Registered User
 
Join Date: May 2014
Last Activity: 16 September 2017, 12:49 PM EDT
Posts: 54
Thanks: 13
Thanked 1 Time in 1 Post
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

Code:
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
PHP Code:
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 2014ready
After executing the FTP script got below error


Code:
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.


Moderator's Comments:
FTP script not working Don't post confidential info - here: username / password - even if just valid for a private network.

Last edited by RudiC; 06-19-2017 at 05:00 AM.. Reason: obfuscated confidential data
Sponsored Links
    #2  
Old Unix and Linux 06-19-2017
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 20 October 2017, 11:53 AM EDT
Location: Lancashire, UK
Posts: 3,307
Thanks: 1,417
Thanked 648 Times in 584 Posts
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
The Following User Says Thank You to rbatte1 For This Useful Post:
Riverstone (06-20-2017)
Sponsored Links
    #3  
Old Unix and Linux 06-19-2017
hicksd8 hicksd8 is offline Forum Staff  
Moderator
 
Join Date: Feb 2012
Last Activity: 21 October 2017, 5:37 PM EDT
Location: Devon, UK
Posts: 1,531
Thanks: 224
Thanked 391 Times in 329 Posts
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:


Code:
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:


Code:
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.
The Following User Says Thank You to hicksd8 For This Useful Post:
Riverstone (06-20-2017)
    #4  
Old Unix and Linux 06-20-2017
Riverstone Riverstone is offline
Registered User
 
Join Date: May 2014
Last Activity: 16 September 2017, 12:49 PM EDT
Posts: 54
Thanks: 13
Thanked 1 Time in 1 Post
Quote:
You might get away with just adding passive to you list of commands before you try to put the file.
I have added and tried issue still remain same as below


Code:
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.


Code:
 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




Quote:
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 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 ----------

.................
Sponsored Links
    #5  
Old Unix and Linux 06-20-2017
hicksd8 hicksd8 is offline Forum Staff  
Moderator
 
Join Date: Feb 2012
Last Activity: 21 October 2017, 5:37 PM EDT
Location: Devon, UK
Posts: 1,531
Thanks: 224
Thanked 391 Times in 329 Posts
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?

Last edited by hicksd8; 06-20-2017 at 04:34 AM..
The Following 2 Users Say Thank You to hicksd8 For This Useful Post:
rbatte1 (06-20-2017), Riverstone (06-20-2017)
Sponsored Links
    #6  
Old Unix and Linux 06-20-2017
Riverstone Riverstone is offline
Registered User
 
Join Date: May 2014
Last Activity: 16 September 2017, 12:49 PM EDT
Posts: 54
Thanks: 13
Thanked 1 Time in 1 Post
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.
Sponsored Links
    #7  
Old Unix and Linux 06-20-2017
hicksd8 hicksd8 is offline Forum Staff  
Moderator
 
Join Date: Feb 2012
Last Activity: 21 October 2017, 5:37 PM EDT
Location: Devon, UK
Posts: 1,531
Thanks: 224
Thanked 391 Times in 329 Posts
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.)

Last edited by hicksd8; 06-21-2017 at 02:43 AM..
The Following 2 Users Say Thank You to hicksd8 For This Useful Post:
rbatte1 (06-21-2017), Riverstone (07-21-2017)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
expect script inside shell script not working. bhavesh.sapra Shell Programming and Scripting 2 10-23-2012 03:43 AM
Script not working in cron but working fine manually jasperux Shell Programming and Scripting 2 07-05-2012 12:37 AM
Script is not working from cron while working manually anuragpgtgerman Shell Programming and Scripting 3 01-23-2012 01:54 PM
Perl script 'system' linking to local shell script not working phpfreak Shell Programming and Scripting 5 10-16-2009 04:56 AM
Script not working..."sort" not working properly.... Rahulpict Shell Programming and Scripting 23 03-16-2009 11:13 AM



All times are GMT -4. The time now is 10:33 PM.