Followed this thread ...
https://forum.arduino.cc/t/ftp-upload-sim7600/931213/2
And have all of the steps working except when I try to upload the file it fails.
So pretty much the code takes the jpg adds to SD and then EFS then I need it to upload from EFS to FTP over GPRS/4G.
CFTPSPUTFILE uploads from EFS to FTP.
Ran up a simple FTP server to see the logs (below) and I dont see the transfer starting.
Added AAA to the file below that I know is on both the SD and EFS to see what the result was which was the same. The AAA means the file doesn't exist hence was expecting error of file doesn't exist but thats not the case. So to me CFTPSPUTFILE is not reading EFS and/or my code below is wrong?
AT+CFTPSPUTFILE="/AAA181122163750.jpg",3
Command ? shows the format you need to use
modem.sendAT("+CFTPSPUTFILE=?"); //shows the format
result:
22:03:55.906 -> +CFTPSPUTFILE: [{non-ascii}]"FILEPATH"[,(1-3),(0-2147483647)]
Command
AT+CFTPSPUTFILE=”/LK/LM/sim_ZXX.TXT”
Code
modem.sendAT("+CFTPSPUTFILE=\"/181122163750.jpg\",3");
Any advice? I need to be able to prove if the CFTPSPUTFILE is reading the file hence how can I get more debug info than my code below or other way to do this?
modem.sendAT("+CFTPSPUTFILE=\"/181122163750.jpg\",3"); //AT+CFTPSPUTFILE=”/LK/LM/sim_ZXX.TXT”
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSPUTFILE upload failed!");
}
else {
(modem.waitResponse() == 0);
pDBG(res);
pDBGln("Uploaded photo successful");
}
FTP Code block
void FTP4G_upload() { // Tiny GSM doesnt support 4G FTP
String res;
Serial.println("Starting the FTP process...");
const char *f_name = pic_name.c_str();
//FTP Start
modem.sendAT("+CFTPSSTART"); //used to start FTP
modem.waitResponse(1000L);
pDBG(res);
if (modem.waitResponse(10000L) != 0) { //x is not equal to y
pDBGln("+CFTPSSTART failed to start");
delay(500);
pDBGln("+CFTPSSTART retrying...");
modem.sendAT("+CFTPSSTART"); //try again
modem.waitResponse(10000L);
pDBG(res);
return;
}
else {
(modem.waitResponse() == 0);
pDBG(res);
pDBGln("+CFTPSSTART started");
}
//FTP Login
modem.sendAT("+CFTPSLOGIN=\"", ftp_serverIP, ("\","), 21,(",\""), ftp_user,("\",\""), ftp_pass,("\","),0); //0 is FTP
if (modem.waitResponse(2000L) != 1) {
pDBGln("+CFTPSLOGIN Failed");
modem.waitResponse(10000L);
pDBG(res);
return;
}
else {
(modem.waitResponse() == 0);
pDBG(res);
pDBGln("+CFTPSLOGIN Logged in!");
}
//Set FTP Type to binary
modem.sendAT("+CFTPTYPE=", ftp_type);
modem.waitResponse(1000L, res);
pDBG(res);
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSTYPE Fail");
}
//Change Directory
modem.sendAT("+CFTPSCWD=\"", ftp_pwd,("\"")); //AT+CFTPSCWD /domain.com/Camera
modem.waitResponse(1000L, res);
pDBG(res);
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSCWD set folder Fail");
}
//Confirm Current Directory
modem.sendAT("+CFTPSPWD"); //AT+CFTPSPWD /droidblast.com/Camera
modem.waitResponse(1000L, res);
pDBG(res);
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSPWD current folder");
}
//List Files
Serial.println("List Files on FTP Host");
modem.sendAT("+CFTPSLIST=\"", ftp_list,("\"")); //AT+CFTPSLIST=”/”
modem.waitResponse(1000L, res);
pDBG(res);
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSLIST Fail");
}
//Initialize EEPROM with predefined size
EEPROM.begin(EEPROM_SIZE);
pictureNumber = EEPROM.read(0) + 1;
//Path where new picture will be saved in SD Card
String path = (("/Camera/") + String(f_name)); //e.g., /Camera/121122214936.jpg
Serial.println(path);
fs::FS &fs = SD;
Serial.println(f_name);
File file = fs.open(path.c_str(), FILE_WRITE);
if(!file){
Serial.println("Failed to open file in writing mode");
}
else {
file.write((unsigned char*)tempImageBuffer, ImgMetaData.imSize); //char* to access any type of object in C++
Serial.printf(f_name, path.c_str());
Serial.println("");
EEPROM.write(0, pictureNumber);
EEPROM.commit();
}
file.close();
//List files on the SDCard
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
if( !SD.exists("/Camera") ) {
SD.mkdir("/Camera");
pDBGln("Photos folder created...");
}
//root = SD.open("/");
root = SD.open(("/"),(CAMERA_Folder));
Serial.println(root);
Serial.println("Listing files on SDCard in Camera folder!");
printDirectory(root, 0);
//Make a new Directory
modem.sendAT("+FSMKDIR=?"); //AT+FSCD=E: AT+FSMKDIR=SIMTech
modem.waitResponse();
pDBG(res);
Serial.println("Create Camera Folder");
modem.sendAT("+FSMKDIR=Camera"); //AT+FSCD=E: AT+FSMKDIR=SIMTech
if (modem.waitResponse(10000L) != 0) {
pDBGln("Camera Folder Exists");
}
else {
(modem.waitResponse(10000L) == 0);
pDBGln("Camera Folder Created");
}
//Select a directory
Serial.println("FSCD select dir");
//modem.sendAT("+FSCD=E:"); //AT+FSCD=E:
modem.sendAT("+FSCD=E:/Camera"); //AT+FSCD=E:
modem.waitResponse();
pDBG(res);
//Return current directory
Serial.println("FSCD current dir is");
modem.sendAT("+FSCD?");
modem.waitResponse();
//Transfer the image from SD card to EFS Cant get to work? ERRORs and causes a network disconnect but copies the file to EFS
//modem.sendAT("+CFTRANRX=\"", "e:", ("/"),(CAMERA_Folder),("/"),(f_name), ("\","),ImgMetaData.imSize);
// modem.sendAT("+CFTRANRX=\"", "E:/",(CAMERA_Folder),("/"),(f_name), ("\","),ImgMetaData.imSize); //AT+CFTRANRX=”c:/MyDir/t1.txt”,10
// modem.waitResponse(10000L);
// pDBG(res);
//List directories/files in current directory
modem.sendAT("+FSLS=0"); //+FSLS: FILES:
modem.waitResponse();
pDBG(res);
//Check AT+FSMEM size of available memory
pDBGln("FSMEM |E:Total Mem|Used Mem");
modem.sendAT("+FSMEM"); //AT+FSMEM Cant get to work?
modem.waitResponse();
pDBG(res);
//List Files
Serial.println("List Files on FTP Host");
modem.sendAT("+CFTPSLIST=\"", ftp_list,("\"")); //AT+CFTPSLIST=”/”
modem.waitResponse(1000L, res);
pDBG(res);
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSLIST Fail");
}
modem.sendAT("+CFTPSPUTFILE=?");
modem.waitResponse(1000L, res);
pDBG(res);
//modem.sendAT("+CFTPSPUTFILE=\"/AAA181122163750.jpg\",3"); result file doesnt exist same result if file exisits
modem.sendAT("+CFTPSPUTFILE=\"/181122163750.jpg\",3"); //AT+CFTPSPUTFILE=”/LK/LM/sim_ZXX.TXT”
if (modem.waitResponse(10000L) != 0) {
pDBGln("+CFTPSPUTFILE upload failed!");
}
else {
(modem.waitResponse() == 0);
pDBG(res);
pDBGln("Uploaded photo successful");
}
//Logout of the FTP server
modem.sendAT("+CFTPSLOGOUT"); //used to stop FTP AT+CFTPSLOGOUT
modem.waitResponse(10000L);
pDBG(res);
if (modem.waitResponse(1000L) != 0) { //x is not equal to y
pDBGln("+CFTPSLOGOUT Failed to logout");
delay(500);
pDBGln("+CFTPSLOGOUT retrying...");
modem.sendAT("+CFTPSLOGOUT"); //try again
modem.waitResponse(10000L);
pDBG(res);
return;
}
else {
(modem.waitResponse() == 0);
pDBG(res);
pDBGln("+CFTPSLOGOUT logged out successfully");
}
//Stop the FTP service
modem.sendAT("+CFTPSSTOP"); //Check if the FTP service is running
modem.waitResponse(1000L);
pDBG(res);
if (modem.waitResponse() != 0) {
pDBG(res);
pDBGln("+CFTPSSTOP failed to stop ");
modem.sendAT("+CFTPSSTOP");
modem.waitResponse(10000L);
pDBG(res);
return;
}
else {
(modem.waitResponse() == 0);
pDBG(res);
pDBGln("+CFTPSSTOP service stopped successfully");
}
}
Result
22:03:02.683 -> +CFTPSSTART started
22:03:02.683 -> AT+CFTPSLOGIN="x.x.x.x",21,"FTPuser","xxxxxxx",0
22:03:02.683 -> OK
22:03:03.681 -> +CFTPSLOGIN Logged in!
22:03:03.681 -> AT+CFTPTYPE=I
22:03:03.731 -> OK
22:03:06.374 -> +CFTPSLOGIN: 0
22:03:13.690 -> AT+CFTPSCWD="/domain.com/Camera"
22:03:13.736 -> OK
22:03:13.829 -> +CFTPSCWD: 0
22:03:23.715 -> AT+CFTPSPWD
22:03:23.715 -> OK
22:03:23.943 -> +CFTPSPWD: "/domain.com/Camera"
22:03:33.753 -> List Files on FTP Host
22:03:33.753 -> AT+CFTPSLIST="/domain.com/Camera"
22:03:33.753 -> OK
22:03:34.008 -> +CFTPSLIST: DATA,68
22:03:34.008 -> -rw-rw-rw- 1 ftp ftp 0 Nov 22 18:53 201122131526.jpg
22:03:34.044 -> +CFTPSLIST: 0
22:03:43.722 -> /Camera/211122210251.jpg
22:03:43.762 -> 211122210251.jpg
22:03:43.937 -> 211122210251.jpg
22:03:44.027 -> Initializing SD card...
22:03:44.027 -> initialization done.
22:03:44.027 -> 1
22:03:44.067 -> Listing files on SDCard in Camera folder!
22:03:44.067 -> /System Volume Information/
22:03:44.067 -> /System Volume Information/WPSettings.dat 12
22:03:44.067 -> /System Volume Information/IndexerVolumeGuid 76
22:03:44.107 -> /Camera/
22:03:44.153 -> /Camera/191122202333.jpg 17018
22:03:44.191 -> /Camera/191122203204.jpg 18836
22:03:44.237 -> /Camera/191122204215.jpg 18121
22:03:44.237 -> /Camera/181122163750.jpg 18093
22:03:45.768 -> AT+FSMKDIR=?
22:03:45.768 -> OK
22:03:45.768 -> Create Camera Folder
22:03:45.768 -> AT+FSMKDIR=Camera
22:03:45.768 -> Camera Folder Exists
22:03:45.768 -> FSCD select dir
22:03:45.768 -> AT+FSCD=E:/Camera
22:03:45.810 -> +FSCD: E:/Camera/
22:03:45.810 -> OK
22:03:45.810 -> FSCD current dir is
22:03:45.810 -> AT+FSCD?
22:03:45.810 -> +FSCD: E:/Camera/
22:03:45.810 -> OK
22:03:45.810 -> AT+FSLS=0
22:03:45.853 -> +FSLS: SUBDIRECTORIES:
22:03:45.853 -> Camera
22:03:45.853 -> +FSLS: FILES:
22:03:45.853 -> 191122204817.jpg
22:03:45.853 -> 181122163750.jpg
22:03:45.853 -> 181122091603.jpg
22:03:45.853 -> 191122204215.jpg
22:03:45.853 -> 181122090918.jpg
22:03:45.853 -> OK
22:03:45.853 -> FSMEM |E:Total Mem|Used Mem
22:03:45.853 -> AT+FSMEM
22:03:45.897 -> +FSMEM: E:(22429696,401408)
22:03:45.897 -> OK
22:03:45.897 -> List Files on FTP Host
22:03:45.897 -> AT+CFTPSLIST="/domain.com/Camera"
22:03:45.897 -> OK
22:03:49.915 -> +CFTPSLIST: DATA,68
22:03:49.915 -> -rw-rw-rw- 1 ftp ftp 0 Nov 22 18:53 201122131526.jpg
22:03:49.915 ->
22:03:49.915 -> +CFTPSLIST: DATA,63
22:03:49.915 -> -rw-rw-rw- 1 ftp ftp 7296 Apr 13 2022 easter.jpeg
22:03:49.915 ->
22:03:49.915 -> +CFTPSLIST: 0
22:03:55.906 -> AT+CFTPSPUTFILE=?
22:03:55.906 ->
22:03:55.906 -> +CFTPSPUTFILE: [{non-ascii}]"FILEPATH"[,(1-3),(0-2147483647)]
22:03:55.949 -> OK
22:03:55.949 -> AT+CFTPSPUTFILE="/AAA181122163750.jpg",3
22:03:57.456 -> OK
22:03:57.456 -> +CFTPSPUTFILE upload failed!
22:03:57.456 -> AT+CFTPSLOGOUT
22:03:57.456 -> OK
22:03:57.536 -> +CFTPSLOGOUT: 0
22:03:59.459 -> OK
22:03:59.459 -> +CFTPSLOGOUT logged out successfully
22:03:59.459 -> AT+CFTPSSTOP
22:03:59.503 -> +CFTPSSTOP: 0
22:03:59.503 -> OK
22:04:01.486 -> +CFTPSSTOP service stopped successfully
22:04:05.472 -> AT+CGREG?
22:04:05.505 -> +CGREG: 0,1
22:04:05.505 -> OK
22:04:05.505 -> AT+CIPRXGET=4,0
22:04:05.505 -> +CIPRXGET: 4,0,114
22:04:05.505 -> OK
22:04:05.505 -> AT+CIPSEND=0,2
FTP DEbug
<Date> Info [Type] Message
<23/11/2022 10:03:47 PM> FTP Session 34 0.0.0.0 FTPuser [Response] 150 About to start data transfer.
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] session::on_socket_event(): source = data listen, flag = 2, error = 0, state = -1
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] CHANNEL state is being dumped:
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] PIPE((IN)) {
max_num_loops_ = 10
thread_safe_ = 0
variant_buffer_ = <2>
variant_adder_ = <2>
variant_consumer_ = <2>
buffer_ = 0x20163091528
adder_ = 0x0
consumer_ = 0x0
waiting_for_adder_event_ = 0
consumer_error_ = 0
adder_error_ = 0
}
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] PIPE((OUT)) {
max_num_loops_ = 10
thread_safe_ = 0
variant_buffer_ = <2>
variant_adder_ = <2>
variant_consumer_ = <2>
buffer_ = 0x201630913f0
adder_ = 0x0
consumer_ = 0x0
waiting_for_adder_event_ = 0
consumer_error_ = 0
adder_error_ = 0
}
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] data_socket_->shutdown() = 0
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Response] 226 Operation successful
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] session::close_data_connection(): there_was_a_transfer_going_on = 1
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser [Trace] Removed done events: 0
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser/Done Event [Trace] CHANNEL state is being dumped:
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser/Done Event [Trace] PIPE((IN)) {
max_num_loops_ = 10
thread_safe_ = 0
variant_buffer_ = <2>
variant_adder_ = <2>
variant_consumer_ = <2>
buffer_ = 0x20163091528
adder_ = 0x0
consumer_ = 0x0
waiting_for_adder_event_ = 0
consumer_error_ = 0
adder_error_ = 0
}
<23/11/2022 10:03:49 PM> FTP Session 34 0.0.0.0 FTPuser/Done Event [Trace] PIPE((OUT)) {
max_num_loops_ = 10
thread_safe_ = 0
variant_buffer_ = <2>
variant_adder_ = <2>
variant_consumer_ = <2>
buffer_ = 0x201630913f0
adder_ = 0x0
consumer_ = 0x0
waiting_for_adder_event_ = 0
consumer_error_ = 0
adder_error_ = 0
}
<23/11/2022 10:03:57 PM> FTP Server [Status] Session 34 ended gracefully.
<23/11/2022 10:03:57 PM> FTP Session 34 0.0.0.0 [Trace] Session 0x20163090010 with ID 34 destroyed.