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
 
Is there only one file at a time in the directory? If so, you could use the findfirst command to get the filename of the first (only) file in the directory. You would then reference that file by using the $FILESPEC command in the sendfile and delfile commands. Just replace MicsFile in those two calls and you should be good to go.


aspect@aspectscripting.com
 
Thanks Knob,

That sounds like the way, but can you show me? I have spent 3 days just getting this far. Procomm Plus is very new to me. Also how can I move a copy to the c:\micsdata\sent folder?
 
Here is a script that shows how to search for the file using findfirst, uploads it, copies the file to the sent directory, then deletes the file (it should drop right into your script):

proc main
#define MicsFile "C:\MicsData\Send\*.zip" ;File to upload.

if findfirst MicsFile
sendfile ZMODEM $FILESPEC ;Send the file with ZMODEM.
while $xferstatus ;Pause script while transferring file.
yield
endwhile
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
endif
endproc

aspect@aspectscripting.com
 
How can I make it so that if failure or disconnect during the transfer that the file is not sent to the sent directory. Also do I have anough check and balances in the script before the transfer part incase of failure or disconnect.

;*****************************************************************************
;* 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 "Unable to connect to Mics server. Please try again later."
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 "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
exit ;exits the script file
else
transmit Password
transmit "^M"
endif
waitfor "Choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
exit ;exits the script file
else
transmit "U" ;Select Upload Menu.
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
exit ;exits the script file
else
transmit "Z" ;Select ZMODEM protocol.
endif
waitfor "name?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
exit ;exits the script file
else
pause 1
if findfirst MicsFile ;Check to see if the file exists.
sendfile ZMODEM $FILESPEC ;Send the file with ZMODEM.
while $xferstatus ;Pause script while transferring file.
yield
endwhile
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
endif
endif
pause 1
transmit "G" ;Select goodbye.
hangup ;Hangup the phone line.
clear ;Clear the terminal window.
pause 2
pwexit ;Close Procomm Plus.
endproc
 
I think you have enough error checking before the file transfer that you should be OK. Here is how to check the status of the file transfer and then perform the necessary steps depending on the outcome:

iStatus = $XFERSTATUS
while iStatus==1 ;Pause script while transferring file.
yield
iStatus=$XFERSTATUS
endwhile
if iStatus == 2
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
elseif iStatus ==3
;Transfer failed for some reason, perform the necessary steps
endif

This would also require that you add an integer variable iStatus at the beginning of your script.


aspect@aspectscripting.com
 
Here what I got and it still don't work. I know it is probably something simple. It still moves the file even if the tranfer is cancelled.

;*****************************************************************************
;* 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

integer iStatus

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."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
endif
waitfor "FULL Name:" ;Waitfor login name prompt.
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit LoginID ;Transmit the login name.
transmit "^M" ;Transmit a CR.
endif
waitfor "correct (Y/N)?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Y"
endif
waitfor "Password:"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit Password
transmit "^M"
endif
waitfor "Choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "U" ;Select Upload Menu.
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Z" ;Select ZMODEM protocol.
endif
waitfor "name?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
pause 1
if findfirst MicsFile ;Check to see if the file exists.
sendfile ZMODEM $FILESPEC ;Send the file with ZMODEM.
iStatus = $XFERSTATUS
while iStatus==1 ;Pause script while transferring file.
yield
iStatus=$XFERSTATUS
endwhile
if iStatus == 2
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
elseif iStatus ==3
;Transfer failed for some reason, perform the necessary steps
endif
endif
endif
pause 1
transmit "G" ;Select goodbye.
hangup ;Hangup the phone line.
clear ;Clear the terminal window.
pause 2
pwexit ;Close Procomm Plus.
endproc
 
I was doing some troubleshooting on file transfers in the host script a couple weeks ago, and for some reason was getting similar errors when I cancelled the transfer. I talked to the developer of ASPECT, he did a little digging, and said it was a bug, but that it only happened if the sender cancelled if I recall correctly. So unfortunately, I don't think you're doing anything wrong, you've run into a bug.


aspect@aspectscripting.com
 
Wizard Knob,

I'am in need of your assistance once again. I need to have the ability to download all files in the \send directory or if there is no files then continue to the download part of the script. Also I have tried to set the download path and procomm continues to use the default path???? Any suggestions?

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

#define PhoneNum "17578243893" ;Phone Number to dial.
#define LoginID "mics" ;Login Name.
#define Password "sampson" ;Login Password.
#define MicsFile "C:\MicsData\Send\*.zip" ;File to upload.
#define MicsUpdate "*.zip" ;File to download.
#define DownloadDir "C:\MicsData\Receive" ;Directory to save the file.

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

integer iStatus

set dnldpath DownloadDir ;Download directory where files are saved.
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."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
endif
waitfor "FULL Name:" ;Waitfor login name prompt.
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit LoginID ;Transmit the login name.
transmit "^M" ;Transmit a CR.
endif
waitfor "correct (Y/N)?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Y"
endif
waitfor "Password:"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit Password
transmit "^M"
endif
waitfor "Choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "U" ;Select Upload Menu.
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Z" ;Select ZMODEM protocol.
endif
waitfor "name?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
pause 1
if findfirst MicsFile ;Check to see if the file exists.
sendfile ZMODEM $FILESPEC ;Send the file with ZMODEM.
iStatus = $XFERSTATUS
while iStatus==1 ;Pause script while transferring file.
yield
iStatus=$XFERSTATUS
endwhile
if iStatus == 2
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
elseif iStatus ==3
;Transfer failed for some reason, perform the necessary steps
endif
endif
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "D" ;Select ZMODEM protocol.
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Z" ;Select ZMODEM protocol.
waitfor "File na"
transmit "*.zip"
transmit "^M"
iStatus = $XFERSTATUS
while iStatus==1 ;Pause script while transferring file.
yield
iStatus=$XFERSTATUS
endwhile
endif
pause 1
transmit "G" ;Select goodbye.
hangup ;Hangup the phone line.
clear ;Clear the terminal window.
pause 2
pwexit ;Close Procomm Plus.
endproc
 
zDoes the directory C:\MicsData\Receive exist on the machine? If not, then Procomm cannot set the download directory to that value (since the directory does not exist), and the current setting will remain in effect.

I'm not in a position to test this at the moment, but you should be able to do a sendfile "*.ZIP" (with the path to the directory of course) I believe. I'm not certain which portion of the script you are referring to since it looks like there are two places where you send files, so I need to get a better idea of what part you are looking at.



aspect@aspectscripting.com
 
The directory does exist on the machine. There is currently only 1 part in the script that sends the other is downloading a file. I need to know how to send every file in the micsdata\send directory, and if there are no files to send then continue the script to the download section of the script. The section from transmit "d" down is the download part.
 
I don't see anything wrong in the script relating to setting the download directory and it worked fine on my machine. Try running the following script and see if it displays the expected directory name.

proc main
#define DownloadDir "C:\MicsData\Receive" ;Directory to save the file."

set dnldpath DownloadDir
fetch dnldpath s0
usermsg "%s" s0
endproc

As for the download portion of the script, it should only occur if there are no files to send?


aspect@aspectscripting.com
 
I got the download section to work with the following change listed below. For some reason I had to add getfile ZMODEM to it. Now the only thing else I need to do is to be able to send for than 1 file (say up to 5 or so)that is in the C:\MicsData\Send folder or all files that are in that directory. And if no files are listed in C:\MicsData\Send folder it would continue to the download section of the script.

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

#define PhoneNum "17578243893" ;Phone Number to dial.
#define LoginID "mics" ;Login Name.
#define Password "sampson" ;Login Password.
#define MicsFile "C:\MicsData\Send\*.zip" ;File to upload.
#define DownloadDir "C:\MicsData\Receive" ;Directory to save the file."

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

integer iStatus

set dnldpath DownloadDir
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."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
endif
waitfor "FULL Name:" ;Waitfor login name prompt.
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit LoginID ;Transmit the login name.
transmit "^M" ;Transmit a CR.
endif
waitfor "correct (Y/N)?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Y"
endif
waitfor "Password:"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit Password
transmit "^M"
endif
waitfor "Choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "U" ;Select Upload Menu.
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Z" ;Select ZMODEM protocol.
endif
waitfor "name?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
pause 1
if findfirst MicsFile ;Check to see if the file exists.
sendfile ZMODEM $FILESPEC ;Send the file with ZMODEM.
iStatus = $XFERSTATUS
while iStatus==1 ;Pause script while transferring file.
yield
iStatus=$XFERSTATUS
endwhile
if iStatus == 2
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
elseif iStatus ==3
;Transfer failed for some reason, perform the necessary steps
endif
endif
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "D" ;Select ZMODEM protocol.
endif
waitfor "choice?"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
transmit "Z" ;Select ZMODEM protocol.
waitfor "File na"
if FAILURE
usermsg "Unable to connect to Mics server. Please try again later."
hangup ;hangs up the phone line
pause 2 ;waits two seconds
pwexit ;Close Procomm Plus.
else
pause 1
transmit "*.zip^M"
getfile ZMODEM ;Receive the file with ZMODEM.
iStatus = $XFERSTATUS
while iStatus==1 ;Pause script while transferring file.
yield
iStatus=$XFERSTATUS
endwhile
endif
endif
pause 1
transmit "G" ;Select goodbye.
hangup ;Hangup the phone line.
clear ;Clear the terminal window.
pause 2
pwexit ;Close Procomm Plus.
endproc

 
If you change the *.zip in your declaration of MicsFile to *.* and change the sendfile command to sendfile ZMODEM MicsFile, I think this will do want you want (I wasn't able to test this with my second computer though).


aspect@aspectscripting.com
 
I think you misunderstand what I'am trying to do. I'am trying to send multiple files from the same directory during one session. All these files are .zip files. I also want the script to continue if there are no files to send, and start the download part. TIA
 
I think what I stated will work. The script will check to make sure there is a file in the directory (*.* would have it check for any file, but you can leave it at *.ZIP). Changing the sendfile command to sendfile ZMODEM MicsFile should send all *.ZIP files in that directory (Zmodem support multiple files in one transfer).

Doesn't the script continue with the download now if there are no files to send?


aspect@aspectscripting.com
 
You were right it worked perfect. However the delfile and copyfile commands only delete and copy the first file. How do I make it so that it deletes and moves all the files that it sends? TIA
 
Ah, good point I had forgotten about those operations. Replace these two lines in your script with these:

if findfirst MicsFile
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
while findnext
copyfile $FILESPEC "c:\MicsData\Sent"
delfile $FILESPEC
endwhile
endif

aspect@aspectscripting.com
 
How do I make it so it check to see if a file exists on the host. Currently the download folder on the host is c:/micsdata/send. Is there a way to use findfirst? I don't know how to reference it so it would look on the host for the file. What I want it to do is to exist if no file exists on the host. By the way thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top