FTP sever, how to create and write in a file.txt or .csv

Thank you i appreciate your answers.
i changed the type of deviceName to STRING but it still don’t working.


and also when i connected my PLC with my PC i didn’t find the directorie "D:" as you see in the image FileZila, i tried all the possibilities but anything worked.

i don’t know i think i should create the directory or somthing please help me.

Did you change the value to the deviceName variable too ?

It’s normal FTP server root is on D:/ of you PLC. So in filezilla you see / as the root folder of the FTP server not the file system of the PLC.

1 Like

yes like you said, i changed the value of the deviceName, and the code showing any errors so it works but the plc didn’t create the filder.

i changed the path from this "D:" to this “D:/” and the programme give me anoter error << 20706>>

Use D: and check the errors return from the OpenFile FBK.
Then you should have info that the file didn’t exist

no i add FileCreation in my code and even i do this it still give me an error 2

`CASE step OF

	0: // Créer le fichier
		fbOpen.enable := TRUE;
		fbOpen.pDevice := ADR(deviceName);
		fbOpen.pFile := ADR(fileName);
		fbOpen.mode := 2; // Lecture/écriture (vérifie la valeur dans ta doc)
		fbOpen();

		IF fbOpen.status = 0 THEN
			fbOpen.enable := FALSE;
			step := 1;  // Passer à l'écriture
		ELSIF fbOpen.status = 16#8302 THEN  // Fichier non trouvé
			fbOpen.enable := FALSE;
			step := 10; // Créer le fichier
		ELSE
			status := fbOpen.status;
			step := -1; // Erreur fatale
		END_IF
	10: // Création du fichier
		
		fbCreate.enable := TRUE;
		fbCreate.pDevice := ADR(deviceName);
		fbCreate.pFile := ADR(fileName);
		fbCreate();

		IF fbCreate.status = 0 THEN
			fbCreate.enable := FALSE;
			step := 0;  // Réessayer l'ouverture
		ELSE
			step := -1; // Erreur de création
		END_IF

	1: // Écriture
		fbWrite.enable := TRUE;
		fbWrite.ident := hFile;
		fbWrite.pSrc := ADR(writeBuffer);
		fbWrite.len := SIZEOF(writeBuffer);
		fbWrite.offset := 0;

		fbWrite();

		IF fbWrite.status = 0 THEN
			fbWrite.enable := FALSE;
			step := 2;
		ELSIF fbWrite.status <> 65535 THEN
			status := fbWrite.status;
			step := -1;
		END_IF

	2: // Fermer
		fbClose.enable := TRUE;
		fbClose.ident := hFile;

		fbClose();

		IF fbClose.status = 0 THEN
			fbClose.enable := FALSE;
			step := 3;
		ELSIF fbClose.status <> 65535 THEN
			status := fbClose.status;
			step := -1;
		END_IF

	-1: // Erreur
		// status contient l’erreur

	3: // Terminé avec succès
		;

END_CASE`


this is the signification of the error 20706 not the 20708. this error tell that i have a problem in the mode used in my code i set **

fbOpen.mode = 2 or 3
**
but without any result.

Try set the FileDevice to F: for me the User partition is F: not D:
If you are on AS4.12 your can use USER_PATH instead of a drive letter

Thank You for your support.
The F:/ directory gives the previouse error 20708. and it dosn’t work at all.

USER_PATH instead of a drive letter. How i can use this ?
image

image

i do the same thing but it gives an error that the file doesn’t exist, 20708


and the create function gives me 65535
image
so there is somthing block the FileOpen function, i tried to create directory but without any result.

Please check help of function blocks B&R Online Help

The FileCreate function block give you the file identifier. You don’t need to use FileOpen.

As your screenshot show you successfully create the file. Now you can read or write on it and Close it.

Important : If a file ident is create you need to close it with the FileClose FBK, even if a write or a read failed.

Please check the online help there is complete example for usage: