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!

need script for unix FTP...

Status
Not open for further replies.

dkr1

Technical User
May 22, 2002
35
US
Hi...I am fairly new to Procomm...I need a getfile script to retreive filename "Qte.$$$" from /u/csd/1 on our unix
server, sent to c:\temp. I can currently connect with the FTP screen and drag/drop but I don't want to give others access to all the files.

thanks...
 
Here's an example I grabbed from the Symantec knowledge base, hopefully it will get you going. I've got a better example at home if you need it.

;FTP.WAS Example script with FTP commands.

proc main
FTP local chdir "C:\test\" ;Set the local dir. to C:\test.
FTP remote copyfile "remote.txt" ;Copy a file from remote to local drive.
while $ftpstatus ;While file is being transferred yield.
yield
endwhile
FTP local copyfile "local.txt" ;Copy local file to remote ftp site.
while $ftpstatus ;While file is being transferred yield.
yield
endwhile
endproc
 
Knob,

If it's no trouble, Post your Version.. Getting ready to do some Heavy FTP Scripting.

Thanks

Hank
 
Here's the edited procedure from that script, I cut out some of the extraneous stuff. Some of the variables referenced in the script were globals, so you won't see them declared in this script. It's been a couple years since I've been in this code, but I hope it's stood up OK!

A brief synopsis - the code dials the FTP Connection Directory entry named FaxForward, has some code that determines if the connection was successful or not (similar to what you use for sendfile/getfile with data connections), copies a ZIP file to the server, retrieves the filelist from the FTP server, parses the text file for the ZIP file that was just uploaded (to verify the upload was successful, I believe this was due to the ftp ASPECT command not accurately returing success/failure), and deletes the local ZIP file if the file is on the FTP server. sAlert was a global variable that I updated in a dialog box. I've left these commands in due to the comments possibly being useful. The only change I see that is needed off the top of my head is FTPSuccess needs to be reset somewhere in the procedure. This is probably due to this variable being reset by another procedure.

proc ftpforward ;Procedure to email received faxes, requires FaxForward entry in Connection Directory
integer iStatus ;Integer to hold $FTPCONNECT results
string sData ;String to hold data from filelist file
string sFileSpec ;String to hold path and name of filelist data

dial FTP "FaxForward" ;Make connection to FTP site
iStatus = $FTPCONNECT
while (iStatus < 2) ;Wait until connection is established
yield
iStatus = $FTPCONNECT
endwhile
pause 1
switch iStatus
case 3
sAlert = &quot;Failed to connect to FTP site&quot; ;Print alert message if connect was not successful
endcase
case 2
sAction = &quot;Connected, uploading to FTP site&quot; ;Print success message if connect was successful
ftp local chdir sFaxInbox ;Change local drive to fax inbox
ftp local copyfile sZipName ;Copy ZIP file to FTP site
while $FTPSTATUS ;Loop while file is being copied
yield
endwhile
sendkey 0x74 ;Send F5 to Procomm to refresh directory listing
pause 10 ;Pause to let refresh occur
ftp remote filelist sFileSpec ;Get list of files from FTP server
while $FTPSTATUS
yield
endwhile
fopen 0 sFileSpec READ TEXT ;Open list of files from FTP server
while not feof 0 ;Loop while file still has data
fgets 0 sData ;Get line of data from file
if strfind sData sZipName ;If filename matching that of uploaded fax file is found
if delfile sFullZipName ;Delete local copy of fax file
iFTPSuccess = 1 ;Set success flag to true
else ;Unable to delete local ZIP file
sAlert = &quot;Unable to delete local ZIP file&quot; ;Print failure message
endif
exitwhile ;Don't bother searching rest of file
endif
endwhile
fclose 0 ;Close file
delfile sFileSpec ;Delete local copy of FTP filelist
if !iFTPSuccess ;File not uploaded successfully
sAlert = &quot;Failed to upload file to FTP site&quot; ;Print failure message if file was not uploaded successfully
endif
endcase
endswitch
disconnect ;Disconnect from FTP server
endproc
 
knob,

I fumbled around and got a working script...
...much thanks for the info!

dkr1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top