You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First I would like to thank you for this amazing library.
As the title says, I'm getting problem transferring data from my SD card to my server.
My code :
/* FTP client This sketch connects to a FTP server through a MKR GSM 1400 board. Circuit: * MKR GSM 1400 board * Antenna * SIM card with a data plan created 21 Dec 2018 by Tryhus*/// libraries
#include<MKRGSM.h>
#include<GSMFTP.h>
#include<GSMFileSystem.h>
#include<SPI.h>
#include<SD.h>
#include"arduino_secrets.h"// Please enter your sensitive data in the Secret tab or arduino_secrets.h// PIN Numberconstchar PINNUMBER[] = SECRET_PINNUMBER;
// APN dataconstchar GPRS_APN[] = SECRET_GPRS_APN;
constchar GPRS_LOGIN[] = SECRET_GPRS_LOGIN;
constchar GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD;
//this file must be present in the remote directory SECRET_FTP_REMOTE_DIRconst String c_downloadFileName = "downloadFile";
// initialize the library instance
GSMFTP ftp;
GPRS gprs;
GSM gsmAccess;
voidsetup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Starting Arduino FTP client.");
// connection statebool connected = false;
// After starting the modem with GSM.begin()// attach the shield to the GPRS network with the APN, login and passwordwhile (!connected) {
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
connected = true;
}
else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
}
voidloop() {
GSMFTPElem remoteFile;
test("Connect to FTP server",ftp.connect(SECRET_FTP_HOST, SECRET_FTP_USER, SECRET_FTP_PASSWORD, SECRET_FTP_PORT));
test("Change current remote directory",ftp.cd(SECRET_FTP_REMOTE_DIR));
test("Display remote files",ftp.ls(remoteFile, true));
sendSDFile("test.txt", "datalogInFTPServer.txt", 1024);
for (;;)
;
}
booltest(const String& msg, bool function)
{
if (function == true) {
Serial.print("OK - ");
}
else {
Serial.print("ERROR - ");
}
Serial.println(msg);
return function;
}
boolsendSDFile(const String& SDfileName, const String& FTPfileName, uint16_t packetSize)
{
bool ok = true;
int res = 0;
uint32_t remainingBytes = 0;
File file;
char* packet = newchar[packetSize];
if (packet == nullptr) {
Serial.println("Allocation error");
returnfalse;
}
file = SD.open(SDfileName);
if (file == false) {
Serial.println("Failed to open SD file");
goto Err;
}
remainingBytes = file.size();
//Start FTP transfer in stream modeif (ftp.streamInStart(FTPfileName) == false) {
Serial.println("Failed to start FTP transfer");
goto Err;
}
while (remainingBytes > 0) {
uint32_t bytes = (remainingBytes >= packetSize) ? packetSize : remainingBytes;
//read a packet of dataif (file.readBytes(packet, bytes) != bytes) {
Serial.println("Failed to read SD file");
goto Err;
}
//send the packet to the FTP serverif (ftp.streamOut(packet, bytes) == false) {
Serial.println("Failed to send data to FTP server");
goto Err;
}
remainingBytes -= bytes;
}
//wait for the transfer to be completedwhile (res == 0) {
res = ftp.streamOutReady();
}
if (res != 1) {
Serial.println("Failed to send data to FTP server");
goto Err;
}
goto Out;
Err:
ok = false;
Out:
file.close();
if (packet != nullptr) {
delete[] packet;
}
return ok;
}
the Output :
Starting Arduino FTP client.
Initializing SD card...OK - Connect to FTP server
OK - Change current remote directory
drwx--x--- 6 717968 48 4096 May 9 13:46 .
drwx--x--- 6 717968 48 4096 May 9 13:46 ..
-rw-r--r-- 1 717968 717968 128000 May 8 16:11 FileToStream
-rw-r--r-- 1 717968 717968 128 May 8 16:05 myFile.txt
-rw-r--r-- 1 717968 717968 0 May 8 11:53 new_file
drwxr-xr-x 2 717968 717968 6 May 8 11:42 op
drwx--x--- 11 717968 48 4096 May 8 15:56 public_html
drwx--x--- 2 717968 717968 4096 Jul 16 2018 tmp
OK - Display remote files
Failed to start FTP transfer
As the output shows, the Arduino connect successfully to the server via FTP but it always say "Failed to start FTP transfer".
The text was updated successfully, but these errors were encountered:
This library currently does not support FTP, however there is a pull request open for this - I suggest you comment there if that's what you are using: #73
Hi there,
First I would like to thank you for this amazing library.
As the title says, I'm getting problem transferring data from my SD card to my server.
My code :
the Output :
As the output shows, the Arduino connect successfully to the server via FTP but it always say "Failed to start FTP transfer".
The text was updated successfully, but these errors were encountered: