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

FTP batch file commands

Status
Not open for further replies.
Jul 18, 2001
68
US
I'm using a ftp batch file with the mget command to retrieve multiple files from my Unix box to a NT server, is there a command/syntax that I could use in my batch file that would allow me to clean out the UNIX directory of the files that were ftp'd?

Thanks
 
No. An FTP shell only has a limited number of commands available to it and they are all related to file transfer, not file management. The only way to actually effect the files on the Unix box would be to crack your way into the box via ftp, and you don't want to do that, especially if you already have access to the box. d3funct
zimmer.jon@cfwy.com
The software required `Windows 95 or better', so I installed Linux.

 
Thanks for the heads up.
Would you have a recommendation on to do it, maybe in another script or batch file run from the NT box?

Thanks
 
d3funct,

Sorry to disagree, from the Solaris man page for ftp

delete remote-file
[tab]Delete the file remote-file on the remote machine.

also

mdelete remote-files
[tab]Delete the remote-files on the remote machine.

Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
That being the case this does seem a dangerous strategy to me, deleting the original files before checking that they arrived safely and/or ungarbled at the recipient?
 
This may be true as well. Is there maybe a move command that can be used from a ftp scritp? Probably safer to move the files to a different directory rather than delete them.

Thanks
 
There is a rename file1 file2 command available and this will rename files on the remote machine. However, it doesn't appear to be happy if pathnames which span filesystems are included. It is happy to include directory names within the filesystem however, eg

ftp> rename ken newdir/ken

moves file ken to the newdir directory in the same filesystem.

Not sure if this is what you need - is it more of a filesystem space issue? If so, perhaps a cron job to copy the files to another filesystem before the ftp would be more appropriate.

Hope this makes sense and helps!
 
My concern is not space. This directory is used for storing outbound IDOC's for processing, so once I ftp the IDOC's for processing (using the mget idoc* command), I want to move those IDOC's so when the batch/script runs again it will not ftp the same files over and over again.
 
That being the case the option to rename the file above should work. Create a new directory under that which you're transferring from, then put the rename command in your command file after your mget or whatever.

This will effectively 'rename' the files so that they reside in the directory you have created, rather than the one you're ftp'ing from, and won't therefore be picked up again. It would be worth checking that this has worked on a daily basis and having a periodic clearout because regardless of how much space you have, you'll always need more at some stage in the future!

Cheers - let me know if you need more info.

 
Having thought about it some more, there's a flaw in my contribution above in that rename will not rename multiple wildcarded files in the same way as mget will 'mget' them.

This being the case, I'd either write a script to make a directory listing, cat this into an ftp routine to transfer, rename and delete the files individually, or as I suggested earlier, copy the files by means of a cron job before the ftp process to transfer and delete kicks in. Apologies for the confusion of the earlier contribution.
 
If I use a ls -l to show the directory contents, how would incorporate or " cat " this into the rename and delete routine or am I not understanding correctly?
Thanks for all your input on this!!
 
No worries - it's more interesting than work! The short script below should give a flavour of what's required:

ls -f > filelist
for i in `cat filelist`
do
ftp -n <IP Address> <<!
user <username> <password>
cd <remote directory>
put $i
bye
!
mv $i <newdir>
done

I have not used rename in the ftp command list because having misread the man page for ftp, I had not realised that it renames the remote version of the file, not the local one (it was a long day!). The mv command above does the same thing on the local box. You might also grep your filelist (using grep -v) for files which you don't want ftp or mv to process, eg:

cat filelist | grep -v [file not to be transferred] > filelist1

Hope this helps.

 
Sorry - replace the ls -f above with ls -- for a smarter selection of ordinary files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top