Script To automate ftp uploading
royterry at earthlink.net
Tue Sep 12 18:35:38 CEST 2000
Moshe Eshel wrote:
> I need some help to create a script that will connect to a remote server and
> upload all the files in a certain directory.
> I know how to do the basic stuff like the connect and upload issues,
> what I really need help with are all the special cases... How to deal with
> Errors on the remote server, how to know when file upload has finished
> and do a size check to determine if the file made it to the other side...
> And if failed to retry... etc...
> Any help would be appriciated..
I have implemented this sort of thing several times.
Your best bet involving Tcl would be to use the tcllib ftp package
then you can do open,get,ls, etc. from within your script. I've
used it a lot and it appears completely solid. Look for it at
If, for some reason, you don't want to use the native Tcl ftp package
you could use Tcl/Expect to run a command line ftp or you could use
Tcl/Expect/Telnet to run ftp on the remote machine. This last case gives
you the greatest visibility in to errors on the other side and you
could also run checksums, etc., but it is
almost certainly not worth the trouble. Also the expect solutions
UNIX or use of a special 8.0Tcl supporting expect on NT only (which
fine by the way).
In any case you are likely to end up "parsing" the output of an ftp
dir or list command. Here are pointers:
1. Beware of very large files for cases where the byte count is printed
next to the group name w/o intervening spaces.
2. Beware that you may need to swap the 3 date/time fields before you
pass them to clock scan based on whether it's a time + date or a date +
3. Beware (especially) of file names containing spaces, dollar signs or
curly braces. Parse the list line with regexp and capture
all the characters beginning with the first word
following the date fields to end of line as literal file name.
Let me know if you'd like some Tcl code snippets for the above.
As far as handling errors, generally you can only report them and
move on. FTP transfers are almost always completely successful or
are obviously broken. If you want to though you could compare "ls"
output for each file on the remote and the local system (or checksums
as mentioned above).
> Any examples in any shell language Perl or Tcl would be greatly
If you use the tcllib ftp package the examples will look very much
like command line ftp.
> Thanks a lot in advance
> Moshe Eshel
> moshe at u4all.com
More information about the Python-list