Convert AT+CFTPSLOGIN to correct format

Trying to taken this command and revise into my sketch

AT+CFTPSLOGIN=”112.74.93.163”,21,”tmf”,”tmf123”,0

Tried

modem.sendAT("+CFTPSLOGIN=",(ftp_server, ftp_port, ftp_user, ftp_pass,0));

ftp_server = FTP-domain
ftp_port = 21
ftp_user = username
ftp_pass = password

Compliles but doesn't login

+CFTPSSTART: 0

OK

ERROR

My function being called

void FTP4G_upload() { 
  String res; 
  pDBG("Uploading via FTP: ");
  modem.sendAT("+CFTPSSTART"); //used to start FTP(S)
   modem.waitResponse(1000L, res);
   pDBG("FTP Started...");
  
  modem.sendAT("+CFTPSLOGIN=",(ftp_server, ftp_port, ftp_user, ftp_pass,0));
  //AT+CFTPSLOGIN=”112.74.93.163”,21,”tmf”,”tmf123”,0
   modem.waitResponse(1000L, res);
   pDBG("FTP Logging in...");
  //modem.sendAT("+CFTPSCWD=", ("/dir1"));
  // modem.waitResponse(1000L, res);
  //modem.sendAT("+CFTPTYPE", ("I"));
  // pDBG("Changed type to binary ");
  // modem.waitResponse(1000L, res);
  //modem.sendAT("+CFTPSPUTFILE", ("/Camera/test.txt"));
  // modem.waitResponse(1000L, res);
   Serial.println("Done... Waiting next transfer...");
   delay(100);
}
char ftp_server[] = "112.74.93.163";
uint8_t ftp_port = 21;
char ftp_user[] = "tmf";
char ftp_pass[] = "tmf123";

char str[40];

void setup()
{
  sprintf(str, "AT+CFTPSLOGIN=\"%s\",%i,\"%s\",\"%s\",0", ftp_server, ftp_port, ftp_user, ftp_pass);

  Serial.begin(115200);
  Serial.println(str);
}

void loop()
{}

Output...

20:04:16.827 -> AT+CFTPSLOGIN="112.74.93.163",21,"tmf","tmf123",0

Then just...

modem.sendAT(str);

not sure which library you use, but it's likely that the extra parenthesis are playing tricks on you

if modem.sendAT() supports a variable number of parameters ended by a null pointer then removing the parenthesis should solve it, otherwise it's like you had called

  modem.sendAT("+CFTPSLOGIN=",0);

which obviously would not do what you want

➜ I would try with:

  modem.sendAT("+CFTPSLOGIN=",ftp_server, ftp_port, ftp_user, ftp_pass,0);

PS: you'll need to make sure the cString contain the quotes if the output needs to look like this
AT+CFTPSLOGIN=”112.74.93.163”,21,”tmf”,”tmf123”,0


if modem.sendAT() does not supports a variable number of parameters then you need to build the command or send it chunk by chunk (as long as sendAT() does not add a line feed)


EDIT: now thinking about it, seems you want the 0 as well in the command, so likely that sendAT() is not a variadic function.... so likely disregard the first part of the comment

Thanks using the TinyGSM library but this doesnt support FTP so having to use the native built in commands.

AT+CFTPSLOGIN=”<host>”,<port>,”<username>”,”<password>”,server_type>]

Documentation shows

AT+CFTPSLOGIN=”112.74.93.163”,21,”tmf”,”tmf123”,0

OK

+CFTPSLOGIN: 0

Did you read/understand post #2?

Thanks

yes result below but I cant login (FTP over 4G)

AT+CFTPSLOGIN="112.74.93.163",21,"tmf","tmf123",0

SIm 7600 shows the example of

AT+CFTPSLOGIN=?

Which produces this out put

+CFTPSLOGIN: "ADDRESS",(1-65535)[,"USERNAME","PASSWORD"[,(0-3)]]

I dont get a script error just after

modem.sendAT("+CFTPSSTART");

OK

But the

AT+CFTPSLOGIN="112.74.93.163",21,"tmf","tmf123",0

ERROR

Example code is

+CFTPSLOGIN: "ADDRESS",(1-65535)[,"USERNAME","PASSWORD"[,(0-3)]]

trying

modem.sendAT("+CFTPSLOGIN=",ftp_server, ftp_port, ftp_user, ftp_pass,0);

But its not logging in to FTP over 4G. I can ssh to the FTP server so I know those details are correct still think I dont have the CFTPSLOGIN correct.

Uploading via FTP: 

+CFTPSSTART: 0

OK

+CFTPSSTART: 0

OK

ERROR

The example of FTP given is this

//Example of FTP upload/download
AT+CFTPSSTART
OK
+CFTPSSTART: 0
//Start FTP service
AT+CFTPSLOGIN=”255.255.255.255”,21,”user
name”,”password”,0
OK
+CFTPSLOGIN: 0
//Login to a FTP server
AT+CFTPSLIST=”/”
OK
+CFTPSLIST: DATA,175
-rw-r--r-- 1 ftp ftp 121 Mar 11 16:24
124.txt
drwxr-xr-x 1 ftp ftp 0 Jan 13
2020 TEST113
drwxr-xr-x 1 ftp ftp 0 Jan 19
2020 TEST1155
+CFTPSLIST: 0
//List all ms of directory "/"
AT+CFTPSPWD
OK
+CFTPSPWD: "/"
//Get current directory of FTP server
AT+CFTPSGETFILE=”124.txt”
OK
+CFTPSGETFILE: 0
//Download a file from FTP server to module.
AT+CFTPSPUTFILE=”124.TXT”
OK
+CFTPSPUTFILE: 0
//Upload a file to FTP server from module
AT+CFTPSLOGOUT
OK
+CFTPSLOGOUT: 0
//Logout FTP server
AT+CFTPSSTOP
OK

So at this stage I am stuck on the code to login to remote FTP server.

Are your strings contained within quotes(")? Why don't you use the code in post #2?

Can you post ALL your code.

Currently using the code in your post #2

My code is to large to post been working this project for too long now.

// FTP Server credentials
char ftp_server[] = ""; 
char ftp_user[]   = "";
char ftp_pass[]   = "";

uint8_t ftp_port = 21; 
char str[40]; 

void setup()
{

  sprintf(str, "AT+CFTPSLOGIN:\"%s\",%i,\"%s\",\"%s\",0", ftp_server, ftp_port, ftp_user, ftp_pass);

 }

My function

void FTP4G_upload() { // Tiny GSM doesnt support 4G FTP
  String res; 
  Serial.println("Uploading via FTP: ");
  modem.sendAT("+CFTPSSTART"); //used to start FTP(S)
  modem.waitResponse(1000L, res);
  pDBG(res);
  //modem.sendAT("+CFTPSLOGIN=",ftp_server, ftp_port, ftp_user, ftp_pass,0);
  //modem.sendAT("+CFTPSLOGIN=?");
  modem.sendAT(str); //added 27/10/2022
  modem.waitResponse(1000L, res);
  pDBG(res);
  Serial.println(str); //added 27/10/2022
  // modem.waitResponse(1000L, res);
  // pDBGln(res);
  // Serial.print(ftp_server);
  // Serial.print(",");
  // Serial.print(ftp_port);
  // Serial.print(",");
  // Serial.print(ftp_user);
  // Serial.print(",");
  // Serial.println(ftp_pass);
  //modem.sendAT("+CFTPSCWD=", ("/somewhere.com"));
  // modem.waitResponse(3000L, res);
  // pDBG(res);
  //modem.sendAT("+CFTPTYPE", ("I"));
  // modem.waitResponse(1000L, res);
  // pDBG(res);
  //modem.sendAT("+CFTPSPUTFILE", ("/Camera/test.txt"));
  // modem.waitResponse(2000L, res);
  // pDBG(res);
  // pDBG("Uploaded image");
  // pDBG(res);
   Serial.println("Done... Waiting next transfer...");
   delay(100);
}

Response

FTP Upload
Uploading via FTP: 

+CFTPSSTART: 0

OK

+CFTPSSTART: 0

OK

ERROR
AT+CFTPSLOGIN:"112.74.93.16",21,"tmf","tmf123",0
Done... Waiting next transfer...

AT+CFTPSLOGIN:

":" should be "=" ?

changed to

void setup()
{

  sprintf(str, "AT+CFTPSLOGIN=\"%s\",%i,\"%s\",\"%s\",0", ftp_server, ftp_port, ftp_user, ftp_pass);

 }

Output

FTP Upload
Uploading via FTP: 

+CFTPSSTART: 0

OK

+CFTPSSTART: 0

OK

ERROR
AT+CFTPSLOGIN:"112.74.93.16",21,"tmf","tmf123",0
Done... Waiting next transfer...

Still seeing the ":" in the output ?

AT+CFTPSSTART starts the FTP service

  Serial.println("Uploading via FTP: ");
  modem.sendAT("+CFTPSSTART"); //used to start FTP(S)
  modem.waitResponse(1000L, res);
  pDBG(res);

Output is

OK

Serial.println(str); is with ' : ' colon

AT+CFTPSLOGIN:"112.74.93.16",21,"tmf","tmf123",0
  modem.waitResponse(1000L, res);
  pDBG(res);

Output is

ERROR

My point is that the AT+CFTPSLOGIN command should have "=" in it...

Sorry it does

sprintf(str, "AT+CFTPSLOGIN=\"%s\",%i,\"%s\",\"%s\",0", ftp_server, ftp_port, ftp_user, ftp_pass);

my comment

Serial.println(str); is with ' : ' colon

Was the out from the serial print shows

AT+CFTPSLOGIN="....

But I get the ERROR message rather than a OK so cant tell

If I pass that command to my SIM7600... I get the following...

15:38:13.714 -> AT+CFTPSSTART

15:38:13.714 -> OK
15:38:13.714 -> 
15:38:13.714 -> +CFTPSSTART: 0
15:38:18.768 -> AT+CFTPSLOGIN="112.74.93.16",21,"tmf","tmf123",0

15:38:18.803 -> OK
15:38:22.399 -> 
15:38:22.399 -> +CFTPSLOGIN: 10

I think 10 is "network error". Are the credentials valid?

the IP user and password are a example not real.

From a cmd line I can FTP to my server and login and upload a file

10 Network error in my case I return ERROR.

https://www.waveshare.net/w/upload/a/af/SIM7500_SIM7600_Series_AT_Command_Manual_V3.00.pdf

It does take a few seconds to return the 10... see the timestamps above. 4 seconds after the OK response. I use a simple stub program to send commands to the SIM7600.

Maybe you could try it.

#include <SoftwareSerial.h>

#define BAUD 38400

SoftwareSerial softSerial (8, 12);  // Rx, Tx as required.

void setup()
{
  Serial.begin(BAUD);
  softSerial.begin(BAUD);

  Serial.print("Ready @ ");
  Serial.print(BAUD);
  Serial.println(" baud");
}


void loop()
{
    while (Serial.available() > 0)
     softSerial.write(Serial.read());
  
    while (softSerial.available() > 0)
     Serial.write(softSerial.read());
}

Serial.print("AT+CFTPSLOGIN=\""); //Logs into FTPS server
 Serial.print(server);
 Serial.print("\",");
 Serial.print(port);
 Serial.print(",\"");
 Serial.print(user_name);
 Serial.print("\",\"");
 Serial.print(password);
 Serial.println("\"");
 Serial.flush();

https://www.generationrobots.com/media/3G-GPRS-GPS-Arduino-Shield-With-Audio-Video-Kit.pdf
Maybe interesting (I know nothing about that subject...)

Thanks added additional, which shows the the CFTPSLOGIN format wasn't correct. For some reason I get a GURU mediation error with your code in post 2 but will work this out once I have the formatting correct.
Wasnt getting the commas in the serial output

#define DUMP_AT_COMMANDS

Followed ZX80's link which shows the code and below is what I have figured out below.

modem.sendAT("+CFTPSLOGIN=\"", ftp_server, ("\","), ftp_port,(",\""), ftp_user,("\",\""), ftp_pass,("\","),0);

Example in the documentation

AT+CFTPSLOGIN=”112.74.93.163”,21,”tmf”,”tmf123”,0
OK
+CFTPSLOGIN: 0

So now its error free and looks correct but I dont get ...

+CFTPSLOGIN: 0

Noting that yours took up to 4s...

Output

09:43:23.256 -> FTP Upload
09:43:23.256 -> Uploading via FTP: 
09:43:23.256 -> 
09:43:23.256 -> +CFTPSSTART: 0
09:43:23.256 -> 
09:43:23.256 -> OK
09:43:23.301 -> 
09:43:23.301 -> +CFTPSSTART: 0
09:43:23.301 -> 
09:43:23.301 -> OK
09:43:23.301 -> 
09:43:23.301 -> OK
09:43:23.301 -> Done... Waiting next transfer...

Extra debug

09:48:44.770 -> FTP Upload
09:48:44.770 -> Uploading via FTP: 
09:48:44.770 -> AT+CFTPSSTART
09:48:44.770 -> 
09:48:44.770 -> OK
09:48:44.770 -> 
09:48:44.770 -> OK
09:48:44.770 -> AT+CFTPSLOGIN="112.74.93.163",21,"tmf","tmf123",0
09:48:44.817 -> 
09:48:44.817 -> OK
09:48:44.817 -> 
09:48:44.817 -> OK
09:48:44.817 -> 
09:48:44.817 -> OK
09:48:50.808 -> Done... Waiting next transfer...



Code

void FTP4G_upload() { // Tiny GSM doesnt suppory 4G FTP
  String res; 
  Serial.println("Uploading via FTP: ");
  modem.sendAT("+CFTPSSTART"); //used to start FTP
  modem.waitResponse(1000L, res);
  pDBG(res);
  modem.sendAT("+CFTPSLOGIN=\"", ftp_server, ("\","), ftp_port,(",\""), ftp_user,("\",\""), ftp_pass,("\","),0);
  modem.waitResponse(1000L, res);
  pDBG(res);
  delay(5000);
  modem.waitResponse(1000L, res);
  pDBG(res);
   Serial.println("Done... Waiting next transfer...");
   delay(100);
}