Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP host and port number in one parameter to the shell script

Status
Not open for further replies.

kumariaru

IS-IT--Management
Mar 9, 2006
61
AU
Hi All,

Is it possible to assign FTP hostname & portnumber in one parameter? To the current script we have the values are passed via csv file(comma seperated values). This csv file consists of multiple FTP host records and all hosts got default port number. Now for one of our server there is a change in the port number and I am looking whether it possible to assign both host & port in one parameter.

.CSV file structure:

Identifier,Host,Userid,passwrd
param, ,red,hat121
gate, ,gate,gate123

I assigned port number with a space in the file but it did nt work.

gate, 1089,gate,gate123


Script:

ftp -n -v $ftphost > $log_status_file <<SCRIPT
user $ftpuser $ftppass
lcd $path
pwd
epsv off
put $filename $remfile

$ftpfilename $remfile: are passed from different file.


Thanks in advance for the help and advices.

Kumari
 



Try using a "colon":
Code:
gate, www.gate.cu[b][red]:[/red][/b]1089,gate,gate123
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hi

LKBrwnDBA said:
Try using a "colon":
I not remember any FTP client that accepts the port like that. They expect the host name and port port number to be two separate parameters. Given that in the OP's code $ftphost is not quoted, it should work with the space, just as (s)he tried. At least that works for me with the netkit [tt]ftp[/tt] ( Linux port of the BSD [tt]ftp[/tt] ).

Kumari, space our time for guessing and post your code. Also specify which [tt]ftp[/tt] implementation and which shell are you using.


Feherke.
 
Hi

I tired both the options in the script and they did nt work. Manually I am able to connect with a space but not with colon.

It is korn script and ftp is normal (not secured). I would like to post the script but I am restricted not to.

Thanks for the help!

kumari
 
Hi

One more thing I would try is to explicitly separate the host and port :
Code:
[b]while[/b] [navy]IFS[/navy][teal]=[/teal][green][i]','[/i][/green] [b]read[/b] ftpid ftphost ftpuser ftppass[teal];[/teal] [b]do[/b]
  [navy]ftpport[/navy][teal]=[/teal][green][i]"${ftphost#* }"[/i][/green]
  [navy]ftphost[/navy][teal]=[/teal][green][i]"${ftphost% *}"[/i][/green]
  [teal][[[/teal] [green][i]"$ftpport"[/i][/green] [teal]==[/teal] [green][i]"$ftphost"[/i][/green] [teal]]][/teal] [teal]&&[/teal] [navy]ftpport[/navy][teal]=[/teal][green][i]'21'[/i][/green]

  ftp -n -v [green][i]"$ftphost"[/i][/green] [green][i]"$ftpport"[/i][/green] [teal]>[/teal] [navy]$log_status_file[/navy] [teal]<<[/teal]SCRIPT
user [navy]$ftpuser[/navy] [navy]$ftppass[/navy]
lcd [navy]$path[/navy]
pwd
epsv off
put [navy]$filename[/navy] [navy]$remfile[/navy]
SCRIPT

[b]done[/b] [teal]<[/teal] [green][i]'ftpconnection.csv'[/i][/green]
And the CSV would look as you tried it :
Code:
gate,[URL unfurl="true"]www.gate.cu[/URL] 1089,gate,gate123
Tested only partially, with [tt]bash[/tt] and [tt]mksh[/tt].


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top