in reply to Accessing files on a Windows server from *NIX via SMB

Sorry, I can't supply you with a perl thing, but I did relatively recently have to deal with SMB copying files to a unix box, did it in a shell script; attached:

#!/bin/sh thisdir=`pwd` usrname='username' passwrd='password' # There are several areas to fix, the username/password above, and the # server/share name and dns name specifics below, the file to copy, an +d what # that file should be called on this box once the copying is successfu +l # Correct If a file doesn't exist, or the old file is deleted first, + # Behavior then the new file is copied to the desired location, durin +g # the time the file is being copied, we get an error, the # destination file isn't created or modified, and things wor +k # like they should. # # Problem: When doing an SMB copy from a windows share at the same ti +me a # new file is being copied over top of an old one, the resul +ting # copy we get is damaged (the file is zero'ed out from the p +oint # where the new copy started being written over the old). # # Solution: Attempt two copies of the file. If a new file is being co +pied # over the top of the old one, the zero'ed out area(s) will +make # the resulting files different, once the two files are iden +tical, # and larger than zero bytes, then we can be assured that th +e # copy was successful. get_valid_smb_copy() { echo "Attempting to retrieve wlan.ini" if [ -f temp.1 ]; then rm temp.1 fi if [ -f temp.2 ]; then rm temp.2 fi #copy the wlan.ini file from the gcam server share (windows smb co +py) /usr/bin/smbclient //server/sharename -I servers.dns.entry \ -U $usrname%$passwrd -W workgrpORdomain -N -c "get file-to-copy +temp.1" fn=1 smbcnt=0 while [ 0 = 0 ]; do # Nice little function to have $fn occilate between 1 and 2 fn=`expr $fn % 2 + 1` # Remove old attempt before attempting to copy it again. This # prevents problems when the file might disappear for a short # time. The copy attempt fails, but the old file is then still + # left. This way, what ever is in this file after the copy # attempt is guaranteed to be the results of the most recent # copy attempt. if [ -f temp.$fn ]; then rm temp.$fn fi /usr/bin/smbclient //server/sharename -I servers.dns.entry \ -U $usrname%$passwrd -W workgrpORdomain -N -c "get file-to-c +opy temp.$fn" # If we're able to copy the file twice, and the destination fi +les are identical # and they are larger than 0 bytes, then I believe we can say +with certainty, # there have been no problems or errors while copying the file +s if [ -f temp.1 ] && [ -f temp.2 ] && [ ! -z temp.1 ] && [ ! -z + temp.2 ]; then echo -n " Got 2 copies..." if ( cmp -s temp.1 temp.2 ); then echo " Copies identical" break else echo " Copies not identical" fi fi smbcnt=`expr $smbcnt + 1` echo " SMB Copy loop #$smbcnt" if (( $smbcnt == 50 )); then echo "Tried to get a valid SMB copy $smbcnt times, but fai +led; script exiting." exit fi # Allow some small amount of time to pass before allowing the +next # attempt. Otherwise 50 failures could pile up very quickly i +f the # target file is deleted for a relatively short time. sleep 2 done rm temp.2 mv temp.1 resulting-file-name } get_valid_smb_copy echo "File successfully copied to resulting-file-name" exit

-Scott