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

How to assign a file name to a variable for upload / download

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
337
GB
Hello

A previous thread I started worked perfectly for uploading and downloading files from a server.

This was ok if you knew the file name.

The coding I used was this:

Code:
*sendftp.prg

RUN ftp  -i -s:send.txt

The send.txt looks like this:

Code:
open ftp.mywebsite.co.uk
myusername-xxxxxx
mypassword
binary
send test.txt
close
bye
exit

So this works ok if you know the file name however, tables I am now trying to upload will be a variable name for example:

Code:
USE MYTABLE SHARED
mupjobnumb=JOBNUMB
mupjobyear=JOBYEAR
STORE WORKINT TO mupworkint

mjobupload=LTRIM(STR(mupjobnumb))+"-"+LTRIM(STR(mupjobyear))+"-"+ALLTRIM(mupworkint)

* An example of what mjobupload looks like could be 4-2016-SW

Code:
USE MYTABLE SHARED
COPY STRUCTURE TO mjobupload+'.dbf'
CLOSE DATABASES

USE mjobupload+'.dbf' EXCLUSIVE
APPEND FROM MYTABLE FOR RECNO()=mrecno

From here I want to upload the DBF and FPT that has been created from the record appended from MYTABLE: mjobupload+'.dbf' and mjobupload+'.fpt'

I have tried changing the send.txt file to the below which does not upload the relevant files:

Code:
open ftp.mywebsite.co.uk
myusername-xxxxxx
mypassword
binary
send mjobupload+'.dbf'
send mjobupload+'.fpt'
close
bye
exit

The reason for the unique file name is that this will be downloaded by someone else and requires a unique name.

In view of the above, can anyone shed some light on what I am missing?

Thank you

Steve
 
First of all, based on the code you show above,
Code:
RUN ftp  -i -s:send.txt
Since the routine is launched with a RUN it appears as though you are using some 'external' routine to Send your FTP files.

However I might suggest that you build your SEND.TXT file in a different manner.
You cannot merely assume that your 'external' ftp routine will 'know' what the variables in your SEND.TXT file represent and/or how to use them.
Instead you might want to dynamically build your SEND.TXT file within your VFP application using either STRTOFILE() or TEXT/ENDTEXT.

Since I am more familiar with the STRTOFILE() approach you might want to consider something like the following:
Code:
cCrLf = CHR(13) + CHR(10)
* --- Build a String of what needs to be in the SEND.TXT file ---
* --- In this way VFP can fill in the appropriate values from the 'mjobupload' variables ---
cSendTextStr = "OPEN ftp.mywebsite.cc.uk" + cCrLf;
          + "myusername-xxxxxx" + cCrLf;
          + "mypassword" + cCrLf;
          + "binary"  + cCrLf;
          + "send " + mjobupload + ".dbf"  + cCrLf;
          + "send " + mjobupload + ".fpt"  + cCrLf;
          + "close"  + cCrLf;
          + "bye"  + cCrLf;
          + "exit"
* --- Now Write String Out to File (SEND.TXT) ---
STRTOFILE(cSendTextStr, "SEND.TXT")

<from here on, merely use this new Send.Txt as needed>
<and re-create it if/when needed>
Obviously the code above is not tested and is offered as a suggested approach.
You would most likely need to modify it to meet your specific requirements.

Alternatively, I'd recommend you consider using a VFP routine to do so.
Something like:
If you did that, then we could most certainly assist you in how to handle a variable file name.

Good Luck,
JRB-Bldr
 
Since Post Edits are not working, I'll add this comment to my above reply.

You might want to be cautious of just using the filenames alone (as you have shown).

Depending on where the various files are located in relation to where your application is executing, it may be necessary for you to include fully-pathed filenames.

Just something to keep in mind.

Good Luck,
JRB-Bldr

 
Hi JRB-Bldr

I'll give your suggestion a go and post back. I also noticed the edit functionality is not working.

Thank you

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top