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

File Upload Help

Status
Not open for further replies.

chris23426

Technical User
May 9, 2003
14
US
I need help to send a file. This file name changes each time, so I need to be able to just send any filename in that "c:\micsdata\send" directory. The file will always end in .zip. After the file is sent I need it deleted from the c:\micsdata\send directory and moved to the c:\micsdata\sent directory. Here is the script I have so far.

;*****************************************************************************
;* MACRO definitions *
;*****************************************************************************

#define PhoneNum "17578243893" ;Phone Number to dial.
#define LoginID "unit1" ;Login Name.
#define Password "sampson" ;Login Password.
#define MicsFile "C:\MicsData\Send\*.zip" ;File to upload.


;****************************************************************************
;* Main *
;****************************************************************************
proc main

dialnumber DATA PhoneNum ;Dial the specified phone number.
while $dialing ;While dialing the number yield.
endwhile
if !$CARRIER
usermsg "Unable to connect to Mics server. Please try again later."
exit ;exits the script file
endif
waitfor "FULL Name:" ;Waitfor login name prompt.
if FAILURE
usermsg "Login prompt not received. Try again."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
exit ;exits the script file
else
transmit LoginID ;Transmit the login name.
transmit "^M" ;Transmit a CR.
endif
waitfor "correct (Y/N)?"
transmit "Y"
waitfor "Password:"
if FAILURE
usermsg "Password prompt not received. Try again."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
exit ;exits the script file
else
transmit Password
transmit "^M"
endif
waitfor "Choice?"
transmit "U" ;Select Upload Menu.
waitfor "choice?"
transmit "Z" ;Select ZMODEM protocol.
waitfor "name?"
transmit "Data.zip" ;Transmit the file name to upload.
transmit "^M"
waitfor "procedure..."
pause 1
if isfile MicsFile ;Check to see if the file exists.
sendfile ZMODEM MicsFile ;Send the file with ZMODEM.
while $xferstatus ;Pause script while transferring file.
yield
endwhile
endif
delfile MicsFile
pause 1
transmit "G" ;Select goodbye.
hangup ;Hangup the phone line.
clear ;Clear the terminal window.
pause 2
pwexit ;Close Procomm Plus.
endproc
 
There is no direct way for a script to determine if a file is on another machine. If you can request a directory listing of a directory, then your script could parse through that output and see if any files are present.


aspect@aspectscripting.com
 
Could you give me an example of how to check the directory by parsing. Or is there away that after so many seconds that when the file is not downloading to make it disconnect?
 
Can you request a directory listing from the remote machine (are you calling into a machine running Procomm's host script)? If so, if you post what the directory listing looks like, I can show you how to parse it.

A file transfer will timeout on its own if the other side does not start the transfer (this is assuming a download), so you would just need to check the value of $XFERSTATUS (or the temp. variable we are assigning $XFERSTATUS to) after the transfer has ended. If the result was 3, then you know the transfer did not succeed for some reason.


aspect@aspectscripting.com
 
Yes I'am calling into a machine that is running the host script. The directory that I'am trying to check is c:\micsdata\send.
 
Do you have c:\micsdata\send as the default host download directory? If so, I've got a script mostly written that will request the file listing from the host script, then produce the list of available files. I'll post it later tonight.


aspect@aspectscripting.com
 
Yes it is set as the default directory in the Hostutil.
 
Here's the script I came up with. You should be able to rename proc main in the script below, then call it from within your current script if you like. The way this script works is it sends an 'F' to the host script, then an Enter to get a list of all available files (you could change this to *.ZIP^M to get a list of only .ZIP files). The script saves the raw directory output to temp.txt in the capture directory under your Procomm install, then opens that file and parses out each file and saves it to output.txt, also in your capture directory. If you want your script to determine if a file exists on the machine, you could either read the file line by line after it has been saved or compare the value of sTemp to the file you are searching for.

proc main
string sCapPath, sCapFile, sLine, sOutput, sTemp

set capture file "temp.txt"
fetch capture path sCapPath
strfmt sCapFile "%s\temp.txt" sCapPath
strfmt sOutput "%s\output.txt" sCapPath
delfile sOutput
when target 0 &quot;<Enter> to continue, <S> to stop&quot; call SendCR
capture on
transmit &quot;F^M&quot;
waitfor &quot;-End of list.-&quot;
transmit &quot;^M&quot;
when target 0 clear
capture off
fopen 0 sCapFile READ TEXT
while not feof 0
fgets 0 sLine
if strfind sLine &quot;<DIR>&quot;
;comment for spacing
elseif strfind sLine &quot;/&quot;
strdelete sLine 0 1
strtok sTemp sLine &quot; &quot;
fopen 1 sOutput APPEND TEXT
fputs 1 sTemp
fclose 1
endif
endwhile
endproc

proc SendCR
transmit &quot;^M&quot;
endproc

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top