FTP multiple pages to a website


hschir

Recommended Posts

I wish to ftp multiple pages (about 10) using Capture() and FTP.Upload () to website. How do I go about this in a single sequence?

Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

You'll actually probably want two sequences, one acting as a function that blocks while the FTP is in progress. Something like:

function sendFTP(string localfile, string remotefile)
   ftp.strRemoteFile = remoteFile
   ftp.strLocalFile = localFile
   ftp.upload()
   private starttime = systime()
   while (ftp.bytesToTransfer != -1)
	  delay(0.1)
	  if (systime() - starttime > 1)
		 break // transfer failed?
	  endif
   endwhile

Something like that. Then call that function 10 times from your base sequence. You'll need to setup the rest of the FTP parameters there too, or in a startup sequence.

Link to comment
Share on other sites

Thanks for that: So as I understand it:

1. In my start up sequence I declare;

FTP.strServer = "ftp.Myserver.com"
FTP.strUserName = "Myusername"
FTP.strPassword = "Mypassword"

2. Then in another sequence;

While (1)
Capture ("pagefilename","c:/myfile_1.jpg")
Private.strlocalfile = "myfile_1.jpg"
Private.strremotefile = "myfile_1.jpg"
sendFTP (string localfile, string remotefile)


Capture ("pagefilename","c:/myfile_2.jpg")
Private.strlocalfile = "myfile_2.jpg"
Private.strremotefile = "myfile_2.jpg"
sendFTP (string localfile, string remotefile)

//and so on up to myfile_10.jpg

endwhile

3. And of course the function as you described in its own sequence

Link to comment
Share on other sites

You're right about the function you posted - it hangs on the while function ?

Link to comment
Share on other sites

Sorry - I used the wrong terminology - you're right - it times out.

Two questions:

1. As it times out - how do I tell whether the strings have actually been transferred from the calling sequence to function sequence ?

2. I require the files to be transferred to a directory on the website server i.e. /images/myfile1.jpg. What would the code for that be ?

Link to comment
Share on other sites

Well, first of all, the 1 second timeout I provided is probably way too short. You'll need to determine a reasonable number, maybe 30? Note you can use bytestotransfer and bytestransfered to watch the progress. Maybe use a ? statement to display the progress while debugging.

Second, the remote file that you pass to my function should be the path just like what you just posted.

Link to comment
Share on other sites

Thanks for that: So as I understand it:

1. In my start up sequence I declare;

FTP.strServer = "ftp.Myserver.com"
FTP.strUserName = "Myusername"
FTP.strPassword = "Mypassword"

2. Then in another sequence;

While (1)
Capture ("pagefilename","c:/myfile_1.jpg")
Private.strlocalfile = "myfile_1.jpg"
Private.strremotefile = "myfile_1.jpg"
sendFTP (string localfile, string remotefile)


Capture ("pagefilename","c:/myfile_2.jpg")
Private.strlocalfile = "myfile_2.jpg"
Private.strremotefile = "myfile_2.jpg"
sendFTP (string localfile, string remotefile)

//and so on up to myfile_10.jpg

endwhile

3. And of course the function as you described in its own sequence

There's an error with the code:

Private.strlocalfile = "myfile_1.jpg"

Private.strremotefile = "myfile_1.jpg"

Should read:

Private.strlocalfile = "c:\myfile_1.jpg"

Private.strremotefile = "/images/myfile_1.jpg"

I think - haven't tried it yet

Link to comment
Share on other sites

Well here is the code I have at present - without the FTP logon listing which we can assume is happening. This code as it currently stands fails to upload the desired file;

Sequence 1.

while (1)

File.Delete("C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

Page.Capture("EvapTanks","C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

delay(1)

Private.strLocalFile = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg"

Private.strRemoteFile = "/DAQFactory/FieldStation.jpg"

sendFTP(string LocalFile, string RemoteFile)

endwhile

Sequence 2.

function sendFTP (string LocalFile, string RemoteFile)

FTP.strLocalFile = LocalFile

FTP.strRemoteFile = RemoteFile

FTP.Upload ()

private starttime = systime ()

while (ftp.BytesToTransfer != -1)

delay(0.1)

if (systime() - starttime > 30)

break // transfer failed ?

endif

endwhile

Any idea's ?

Link to comment
Share on other sites

Dear Guru - I think you might have to try it yourself to figure out what's going wrong (or right for that matter) and get back to me as I've spent hours on it for a bug that would probaly only take you a minute to solve. Please ?

Link to comment
Share on other sites

Another question:

I have the following logging sequence:

beginlogging(Field_Sensor_Log)

// loop forever:

while (1)

waituntil(23h59m)

delay(60)

// set logging file name:

logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files\Daily_Field_Log_" + formatdatetime("%d_%m_%y",SysTime()) + ".csv "

// and repeat

endwhile

I wish to upload the previous nights csv file to my website - how would you go about that?

Link to comment
Share on other sites

Actually, I can look at it and tell you the first thing that is wrong:

sendFTP (string LocalFile, string RemoteFile)

is the declaration for the function. You don't want to use this format to call the function. You want:

sendFTP(strLocalFile, strRemoteFile)

or simply:

sendFTP("C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg", "/DAQFactory/FieldStation.jpg")

Also, don't use private. notation for variables. Its very deprecated and likely won't be supported for too much longer. Instead, do:

private string strLocalFile

As for your logging. First, consider changing your sequence to change the file to simply:

while (1)
delay(1)
// set logging file name:
logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files\Daily_Field_Log_" + formatdatetime("%d_%m_%y",SysTime()) + ".csv "
// and repeat
endwhile[/CODE]

That's the simplest code for having the file change at midnight short of using an Event. To upload the previous night, consider making the above code into:

private string yesterday

[CODE]while (1)
delay(1)
// set logging file name:

yesterday = logging.Field_Sensor_log.strFileName
logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files\Daily_Field_Log_" + formatdatetime("%d_%m_%y",SysTime()) + ".csv "
if (yesterday != logging.Field_Sensor_log.strFileName)
// new day, so upload yesterday's file
sendFTP(yesterday, "/data/Daily_Field_Log_" + formatdatetime("%d_%m_%y",SysTime() - 86400) + ".csv "
// and repeat
endwhile[/CODE]

Link to comment
Share on other sites

OK - Thanks - I'll give it go and let you know (Now there's a title for a song :-) )

Link to comment
Share on other sites

I just recently aquired a hot-wire sensor ($17.00) from www.moderndevice.com and it took me ages to figure out how to calibrate (they didn't give any clues and I don't think they knew any way - they seemed to be winging it) - any how here's the jist of the post I placed in their forum;

Hi,

After trying a whole host of conversion formula's for the wind sensor (none of which I had any confidence in) I came across this lab. report on hot wire calibration using King's formula, so I tried it - and it worked (sort of). I found that I had to substract 1 from the formula given to calibrate the sensor to zero wind speed - but it works real fine now.

I transposed King's formula to make wind speed the formula to arrive at:

U = ((Value^2/0.2763)^0.4556)-1

where, "Value" is the voltage reading from the wind sensor.

Report Link:

www.ces.clemson.edu/courses/mecommon/sa ... report.pdf

Link to comment
Share on other sites

I changed the code as you suggest to:

while (1)

File.Delete("C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

Page.Capture("EvapTanks","C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

delay(1)

Private string strLocalFile = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg"

Private string strRemoteFile = "/DAQFactory/FieldStation.jpg"

sendFTP(strLocalFile, strRemoteFile)

AND THE FUNCTION TO:

function sendFTP (strLocalFile, strRemoteFile)

FTP.strLocalFile = strLocalFile

FTP.strRemoteFile = strRemoteFile

FTP.Upload ()

private starttime = systime ()

while (ftp.BytesToTransfer != -1)

delay(0.1)

if (systime() - starttime > 30)

break // transfer failed ?

endif

endwhile

But the calling function halted almost immediately ?

Link to comment
Share on other sites

I won't change this until I hear from you as I getting confused - this doesn't work the page capture occurs about every second so I guess the call to sendFTP doesn't even happen?

Calling sequence:

while (1)

FTP.strServer = "myisp"

FTP.strUserName = "me"

FTP.strPassword = "mypasword"

File.Delete("C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

Page.Capture("EvapTanks","C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

delay(1)

Private string strLocalFile = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg"

Private string strRemoteFile = "/DAQFactory/FieldStation.jpg"

sendFTP(strLocalFile, strRemoteFile)

endwhile

The FTPsend function:

function sendFTP(string strLocalFile, string strRemoteFile)

FTP.strLocalFile = strLocalFile

FTP.strRemoteFile = strRemoteFile

FTP.Upload ()

private starttime = systime ()

while (ftp.BytesToTransfer != -1)

delay(0.1)

if (systime() - starttime > 30)

break // transfer failed ?

endif

endwhile

Where to now ?

Link to comment
Share on other sites

Sorry but I must be missing something - I couldn't get the multiple upload to work using the sendFTP function so I revereted to placing all of the required code into a single sequance and it works - for how long I don't know yet, but here's a code snippet I used;

while (1)

private starttime = systime ()

FTP.strServer = "myisp"

FTP.strUserName = "myusernamei"

FTP.strPassword = "mypassword"

File.Delete("C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

Page.Capture("EvapTanks","C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg")

FTP.strLocalFile = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\FieldStation.jpg"

FTP.strRemoteFile = "/DAQFactory/FieldStation.jpg"

FTP.Upload ()

while (ftp.BytesToTransfer != -1)

delay(0.1)

if (systime() - starttime >30)

break // transfer failed ?

endif

endwhile

File.Delete("C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\LabJack.jpg")

Page.Capture("LJ_Sys_Status","C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\LabJack.jpg")

FTP.strLocalFile = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Pages\LabJack.jpg"

FTP.strRemoteFile = "/DAQFactory/LabJack.jpg"

FTP.Upload ()

while (ftp.BytesToTransfer != -1)

delay(0.1)

if (systime() - starttime >30)

break // transfer failed ?

endif

endwhile

//And so on until

endwhile

Link to comment
Share on other sites

As a single sequence it stalls after abour a 1/2 hour and DAQFactory needs a restart ?

Link to comment
Share on other sites

This is why there is DAQConnect (www.daqconnect.com). Using capture and ftp is a marginal way at best of getting your data available on the web.

I can't really say what is wrong without viewing your .ctl document. You likely have a typo somewhere. Change your FTP details before posting.

Link to comment
Share on other sites

This is why there is DAQConnect (www.daqconnect.com). Using capture and ftp is a marginal way at best of getting your data available on the web.

I can't really say what is wrong without viewing your .ctl document. You likely have a typo somewhere. Change your FTP details before posting.

I hope that's what you wanted?

FTP_Upload.ctl

Link to comment
Share on other sites

I'm sorry but I've deleted the function through frustration - but here's what I do have now - but if you find something discloses anything that should remain out of the public domain use your discretion and send me an email you have ny doubts - you have my details

If you want me to start all over again with the function - I will - just ask ...

On the question of DAQConnect - I have an account and scoured it - attempted to get it do what I need but unfortunately I find it user unfriendly (at least to this user) - quirky - and does not fit my clients needs - and on top of that I really don't need the brain drain of navigating something that is less than intuitive and doesn't require another programming subset

Link to comment
Share on other sites

Not quite. I wanted the one with the function.

Also, you might add FTP.Abort() just before the break statement when it times out.

The last .ctl file I sent you didn't include the function - sorry about that!

This .ctl file has the function.

What I have done is to create three sequences, namely:

1. FTP_Startup - logs on to my isp,

2. FTP_Send - the ftp upload function,

3. A_Page_Upload - which contains the multiple captures

You will notice that I only call the function following the first capture - and the remaining capture are uploaded within the sequence.

The capture using the function does not upload - all of the others do - which I left running for an hour succesfully - except for the one that called the function?

Untitled.ctl

Link to comment
Share on other sites

I ter about a must have been lucky - the pages that were uploading in my previous post - still fall off the perch a half hour ?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.