Send a file to remote location via FTP

Having trouble with the SendCommunicationHandleCommand. it will not compile the following without a complaint.

if(Log_FtpOpenStatus == 0)then
if(IsCommunicationOpen(ch_FtpTransfer))then
Log_SendFileStatus = SendCommunicationHandleCommand(ch_FtpTransfer, “send:” Log_sFilePath + Log_sFilenameDay, Log_sRemoteFilePath + Log_sFilenameDay);
Log_FtpCloseStatus = CloseCommunication(ch_FtpTransfer);
endif
endif

It appears to have a problem with using string vars to store the file name and paths when using the send: command.

Ant Ideas what I am missing here?

Whats the error it throws?

Compiling…
Error on line 14: syntax error at or near “Log_sFilePath”
1 error(s), 0 warning(s)

It looks like you’re missing the + between the literal and variable here:

"send:” + Log_sFilePath + ...

2 Likes

According to ChisF, you have to put the entire striing set into a string var and place that in there as the command:
stringVari = “send:” + Log_sFilePath + Log_sFilenameDay + “,” + Log_sRemoteFilePath + Log_sFilenameDay;
Log_SendFileStatus = SendCommunicationHandleCommand(ch_FtpTransfer, stringVari);

I guess I missed the part where it explains this in the docs?

Thanks to all.

It’s here under Using OptoScript, OptoScript Data Types and Variables, Using Strings in the PAC Control Help:

image

“The + operator must be used in an assignment statement.”

2 Likes

No, sorry Phil, the concat wasn’t the issue, tried all those.

Like I said, the entire send: command and all strings, and concats in one string var, then place that in the “command” place holder.

This does cmpile:
Log_sFtpSend = “send:” + Log_sFilePath + Log_sFilenameDay + “,” + Log_sRemoteFilePath + Log_sFilenameDay;
Log_SendFileStatus = SendCommunicationHandleCommand(ch_FtpTransfer, Log_sFtpSend);

This does not compile:
Log_SendFileStatus = SendCommunicationHandleCommand(ch_FtpTransfer, “send:” + Log_sFilePath + Log_sFilenameDay + “,” + Log_sRemoteFilePath + Log_sFilenameDay);

That is an assignment statement (for the string) and is valid.

That is not an assignment statement for the string and is invalid.

I’m pretty sure this has to do with memory allocation at compile time - the Opto compiler doesn’t perform any implicit memory allocation, so string concatenation must be assigned to a string variable so that memory allocation is explicit. At least that is how I understand it.

Very cool, nice to know. As usual, you have the best insights into Opto.

They should maybe have a note in the docs for us dummies that indicates that these parameters cannot be concatenated in the parameter.

Ha - I’ve attempted what you attempted many times myself - since it is allowed in many modern programming languages.