Hi. I am attempting to write a script that copies files from a filesystem shared between two linux boxes (gfs2) to a windows server. The ftp client is installed on the windows box. I can create an ftp connection without issue (netrc is used for authentication)
This is the business need I am addressing: For the next several months a new reporting system is rolling out. It is hosted on Red Hat. There is a temporary business need for certain users to be able to drop reports run on these linux boxes to shared folder on the windows box.
The script should go into the shared drive, ftp files to the windows share, then delete the files on the share drive. They do not have to stay there.
I have a good portion of the script working. My difficulty is with the names of the reports. As this is end user controlled, they can include spaces, special characters, etc. It is not possible to enforce a naming convention through the application.
The script I have so far handles the names with out issue, but, once ftp is invoked, special characters are causing transfers to fail.
The script and output from the problematic area appear below. Any suggestions would be greatly appreciated. Thanks for your help.
Here is the script
On the linux box, the names seem to be handled initially, but are causing issues when in ftp:
DGPickett, thanks for the suggestion. I tried about 10 different iterations of "{f}", but was unsuccessful in getting the full file names to pass to ftp.
As such, I decided to try a different approach. In lieu of looping through the source directory, I placed the filenames in a file using sed. This works fine. The full file paths are listed in the file (though I am as yet unsure if they need to be surrounded by quotes).
I would then like to read each line in the file, and have each line enter the ftp portion of the script so the files are transferred.
The problem I am having is that the script keeps erroring out with syntax error: unexpected end of file with the loops I try to do this with.
I have checked for unclosed parentheses, brackets, quotes, etc. but did not see any.
Here are a few attempts I made at writing a script that would read each line and pass to ftp. I am relatively new to shell scripting so any suggestions would be greatly appreciated. Thanks in advance for your help.
Try 1:
Try 2:
Try 3:
Thanks again for any assistance.
The {} on variables are just for name separation and other optional shell behaviors. The "" around them ensure that when unpacked they are 'one word'. Two separate suggestions/ Try "$line" and "${ftpuploaddir}" and "$f".
Also, if changing $IFS, to keep your shell normal elsewhere, do it in a subshell (...)
The hot tip is to have an ssh client on the windows box, and then you can shuffle between two remote hosts:
or locally:
FTP is many ways klunky.
Thanks again for your help DGPickett. I realize that ftp is not that robust, but I have limited options in terms of permissible technologies where I am.
I nearly have it working. I managed to address the issues with metacharacters and spaces, etc. The for loop below works in that sense. The only issue I have no is that the loop only does one iteration (i.e. if there are 5 files in the source directory only one will be transferred to the windows server).
I would appreciate any other suggestions anyone might have. Thanks again for all your help.
I do a lot less "for var in ". You are foundering on for i in "..." which is one word. How about "ls ... | while read i" instead. I will have the whole line, including any embedded meta, as each read gets one line, and your files are linefeed not white space delimited. For cases like "find ... | while read i" you also get pipeline parallelism, as the loop starts ASAP not after all as in "for i in `find ...`".
Hi,
I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder.
I was planning that All configuration should be done through a properties files. and finally the output should be
Files are transferred
I have developed a properties file named... (4 Replies)
hello ,
I am working on a FTP script which navigates to specific directory and pulls the file
Issue which i am facing ::
----------------------------
i) When there is a file it pulls the file , but when there is not file in the directory it fails in the same statement and it is not... (3 Replies)
Hi all,
I'm using the following script to automated ftp files to 1 ftp servers
host=192.168.0.1
/usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp
open $host
bin
cd ${directory}
put $files
quit
ftp
and the .netrc file contain
machine 192.168.0.1
login abc... (4 Replies)
Hi,
I have a ftp script which first gets all the file names and echo's the latest file.
I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is
> Rename Temp File calloc:ICMP... (5 Replies)
I have the following ftp script to get files from a remote location.
However, on running the script I find that I am not even able to connect to ftp server.
I am able to connect to ftp server using other GUI ftp tools like WS_FTP using the same IP.
IP used here is a dummy IP.
What can go... (3 Replies)
Hello,
A couple of times per week, i receive emails notifications when files are available for processing.
Currently i read these eamails with a java program and store the attachement on my C: drive and would now like to generate a PC script to send this file name up to UNIX-Solaris and... (3 Replies)
I have my ftp script as below..
This is logging the messages into ftp.log file ,
But I want the same output(what ever messages are going into ftp.log) to be printed on the console too for the user to show the status.. Tried with "tee" .. unable to get the solution..
Can some one help me... (3 Replies)
Novice here...
I need help with excuting a shell script on a flat file that I've transfered over from a Windows XP machine for manipulation through an auto FTP script...
so that after it is transfers it excutes the shell script and then returns it back to XP machine...
Any ideas... (2 Replies)
Hello ,
I am trying to make a shell script (Unix) for a ftp connection to another server and to get a file.
So I have no knowledge about ftp and my script must do automaticly the connection with the user and passwd.
Can you help us about that...
Christian... (2 Replies)