Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

FTP client throught a 3G router with IP protocol

Benjamin.vial Nov 29, 2017 12:53 AM


I want to program my CR1000 to do two mains things :

1 - Record 1 file / 3 minutes (this lapse for test) and create a file, store it until this is send by FTP.

2 - Send files(s) in FTP throught the NL120, then a 3G router (netmodule NB1600) that make port mapping.

Of course I want to send all file that wasn't sent since the lance transmission OK, and I want to add a routine that delete file after for example 1 month.

The program works well if I set the CR1000 to send a file in FTP in a local network (on my PC for example), the FTPresult is -1, but when I'm trying on the network, it never works (FTP Result 0).

Have you a basic example to do this ?

I retrieve a colleague program that worked with a GPRS modem in PPP protocol (famous wavecom) so I don't be sure about my command line in my case...


GaryTRoberts Nov 29, 2017 12:31 PM

A good primer has been put together and posted at https://s.campbellsci.com/documents/us/technical-papers/ftp-streaming.pdf.  This technical paper can help you through the FTP CRBasic instructions.  The issue you might be seeing might be resolved by switching from Active to Passive mode or vice-versa.

Sorry, I can't help with the PPP dial strings.

Benjamin.vial Nov 30, 2017 12:24 AM

Hi Garry, thanks for this doc I'll read and try to use it, and I'll come back later.


Benjamin.vial Nov 30, 2017 09:15 AM


i've made minors changes, well, doens't work better.

I switched between active and passive mode, no effect.

There is my program, a lot of commented lines (because the prog used wavecom modem but not me) :


'Declaration des Variables
Public BattV
Public Temp_CR1000_C

' Variable de temps
Public rTime(9)
Alias rTime(1) = Year 'assign the alias Year to rTime(1)
Alias rTime(9) = Day_of_Year 'assign the alias Day_of_Year to rTime(9)
'Public testif As Boolean

'Declaration variables pour FILE QUEUE - empilage des fichiers si la connexion GPRS est mauvaise
Const QL = 50 'queue buffer size - 1 fichier / jour donc 50 jours de buffer
Public Queue(QL) As String * 31
'Public ppp As String * 50
Public Outstat As Boolean, OutStatTrig As Boolean, LastFilename As String * 31
Public NewFileName As String * 50

'Declaration variables pour le FTP
Public FTPResult As Boolean
Public RemoteFileName As String * 50
Const LoggerID="test"
Const IPAddress="ftp"
Const UserName="rapftp"
Const Password="tata"
Public LName As String * 31

'Parametre Modem
'Const GPRS_ModemBaudRate = 115200
'Const GPRS_ModemPort = Com1 Const GPRS_CR = CHR(13)
'Const GPRS_OK = CHR(10)& "OK"

'Declaration des unites
Units BattV=Volts
Units Temp_CR1000_C=deg C

'Declaration tableau de donnees
DataInterval (0,3,Min,1)
Sample (1,Temp_CR1000_C,FP2)
TableFile ("USR:test",8,50,-1,3,min,Outstat,LastFilename)

''''''''''''''''Definition des sous routines''''''''''''''''''''''''''''''
'Sub ModemOFF 'arret du modem
''Send the modem shutdown command, trying up To 3 times To try To ensure the command
''Is actioned.
'SerialOut(GPRS_ModemPort,"AT+CFUN=0" & GPRS_CR,GPRS_OK,3,200)
'Delay(1,5,sec) 'delay a few more seconds just to be sure the modem is offline
'SerialClose(GPRS_ModemPort) 'Release the serial port connection.
''Turn off the modem (where necessary)
'SW12 (0)

'Sub ModemON ' démarrage du modem
'SW12 (1)

' stockage des fichiers en attente d'envoi dans une pile
Sub QueueAdd()
Dim i
If OutStatTrig Then 'add new file to queue
Day_of_Year=Day_of_Year - 1
For I = 1 To QL 'find an empty spot
If Queue(I) = "" Then
Queue(i) = NewFileName
ExitFor 'queued so exit
EndIf 'end if queue
Next I 'end for I
If I > QL Then 'there wasn't room, make some and add
Move (Queue(1),QL-1,Queue(2),QL-1) 'shift queued names down - 2 to 1, 3 to 2, 4 to 3, etc.
Queue(QL) = NewFileName
EndIf 'end if outstatTrig

'enleve le fichier de la pile si celui-ci est envoye
Sub QueueRemove()
Move (Queue(1),QL-1,Queue(2),QL-1) 'shift queued names down - 2 to 1, 3 to 2, 4 to 3, etc.
Queue(QL) = "" 'clear trailing name

'Programme principal
SetStatus ("USRDriveSize",1000000)

'''''''''''''''Boucles secondaires'''''''''''''''''
Scan(1,min,3,0) 'toutes les 1min si creation fichier outstat=True empilage fichier dans la pile
RealTime( rTime )
If Outstat Then
Call QueueAdd() 'a chaque creation de fichier, stockage dans la pile en attendant l'envoi par ftp

'If rTime(4) = 6 AND rTime(5)=15 Then 'Every day at 11:15 am turn on the modem
If (Queue(1) <> "")
Do While (Queue(1) <> "") 'If queue is not empty
LName = Queue(1)
Day_of_Year=Day_of_Year - 1
RemoteFileName="/RTITAN2/AVP/ftp_test/" + LName
If FileTime(LName) > 0 Then 'if file exists
'FTPResult = FTPClient (IPAddress,UserName,Password,LName,RemoteFileName,0) 'attempt to ftp
FTPResult = FTPClient ("ftp","rapftp","tata",LName,RemoteFileName,2,0,0,min,3) 'attempt to ftp
Delay (1,10,Sec)
If FTPResult Then
Call QueueRemove()
ExitDo 'send succeeded or failed, if failed exit while queue and try later
EndIf 'endif ftpresult
Else 'file does not exist
Call QueueRemove()
EndIf 'end if filetime
Loop 'end do while queue
Delay (1,10,Sec) 'Control SlowSequence Execution Frequency


Sorry for the big prog, and french comment sometimes, I maybe lost myself in this jungle !

Thanks for your help.


nsw Dec 4, 2017 10:07 AM

Your program is sending a file, I think, called "LName". But your FTP instruction has been configured to stream data from a table.

The optional parameters ",0,0,min,3" in your instruction are getting the FTP instruction to try to stream data directly from a data table. Just try removing this option to see if this improves the situation.

If not, perhaps you could write a much simpler program which just trys to send one file. You can copy a text file from your PC and put it yourself in the CPU or USR area using "File Control", just so you can prove the FTP instruction works. Once you have proved the FTP worked, you can then move on to implementing it in your main program.

Benjamin.vial Dec 6, 2017 03:30 AM


very good idea you have, so here is my new "simple" prog, :




'Main Program
	'Main Scan
		'Default CR1000 Datalogger Battery Voltage measurement 'BattV'
		'Default CR1000 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
		'107 Temperature Probe measurement 'T107_C'
		'Call Data Tables and Store Data
		CallTable Table1
		CallTable Table2
      FTPResult=FTPClient ("ftp.domain.com", "login", "password", "Table1", "path/to/my/folder//", 0, 0, 1, min, 8, 30)


Of course I have hide the login and ftp address.

And after an half hour, still response "false" in FTPResult.

I will test several ftp option to try.

If you have any idea ...

Thanks, bye.

Benjamin.vial Dec 13, 2017 12:37 AM


FTP push remains stuck, response = 0.

I have tried several FTP mode but it's not seem to be effective.

Do you confirm my "simple program" is working normally ?

I precise that the FTP server get data of a hundred of measure station (but not Campbell for now), so port and protocol seem to be open.

About this : we do not have to enter a port number in the program, why ?

[edit : sorry it's wrote in the help, default port 21, and if different put a colon (like :]

Thanks for your help,


Log in or register to post/reply in the forum.