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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Both way communication in one FTP session.

Status
Not open for further replies.

bharix

Programmer
Aug 6, 2002
23
DE
Hi All,
This is a snippet of my script:
###
ftp -in $SERVER_IP <<-EOF >> $FTP_LOG
user $LOGIN $PASS
cd $DIR_LOC
dir *.* ${FDIRLIST}
! . ${PARSE_SCR} ${FDIRLIST} ${FLIST}
mget $(< $FLIST)
EOF
###
Description:
In one FTP session I get a long listing of the remote
directory and create a file locally with those contents.
Now, I pass this file name to another local script to parse the contents to get the files which are created today at the remote server.
It seems to be not possible for me to read this $FDIRLIST file in the same FTP session and parse it locally.

What is the work-around?

Alternatively,
how could I know &quot;today's&quot; files on the remote server in an
FTP session so that I can mget those particular files?

The files on the remote server don't have date-time stamp in their names.
Do I HAVE to use two FTP session in this case?
Both server are Sun Sol. 5.8

Thanks,
bharix
 
When you are using a Here File (the &quot;cmd <<-EOF ... EOF&quot; construct), all of the [tt]${}[/tt] and [tt]$[/tt] variables are replaced before the [tt]ftp[/tt] is called. That means that if your script you are calling locally is defining any of the variables going to [tt]ftp[/tt], they won't be defined at the time the [tt]ftp[/tt] is called. In other words, the file [tt]${FLIST}[/tt] is being read by the shell before it's created. It's actually trying to read [tt]${FLIST}[/tt] and create that [tt]mget[/tt] line before the [tt]ftp[/tt] is called. I'm not sure if I'm describing it clearly. I'd need to see more code to tell if that's actually the problem.

If it is, you could have one [tt]ftp[/tt] to get the list of files, then exit, process the list of files, then another [tt]ftp[/tt] to do the [tt]mget[/tt].

Alternatively, you could NFS mount the directory that has those files and just [tt]cp[/tt] them. Your script would have access to the actual file dates. Or you could use a [tt]find[/tt] with an [tt]-mtime[/tt] parameter and then [tt]cp[/tt] them from the NFS mounted directory.

Hope this helps!
 
Thanks SamBones - you are correct about ${FLIST} being created
before the ftp call. So I will have to use two ftp sessions in this case. One to read the filenames, second to fetch the files that I am interested in.
NFS option is not viable in my situation since the server where the files are created is a third party shared server with access restricted by FTP only.
Thank you for your help - bharix.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top