ofxFTP - Can't send file to server

Hi,

I’m currenly working on a project where I have to send a .json file to a FTP server. I found ofxFTP for this. But i can’t get a file one my server. After some searching on the forums i found that “Davideo” had the same problem. But no one answered to his problem. http://forum.openframeworks.cc/t/ofxftp-in-xcode-4.2/9241/1

Any one idea how to fix this? Or an alternative way of uploading a file to FTP server?

Thanks,

Julien

the way i usually handle networking things like this with OF is to write a shell script or python script that does what i want, and then call it from OF using ofSystem()

Thanks for the replay. But i managed to get it working :slight_smile:

If you comment out “ftp->setFileType(type);” in ofxFTPClient::send() (found in ofxFTP.cpp) it will work.

  
  
void ofxFTPClient::send(string local, string remote, bool is_binary)  
{  
	ostream& ftpOStream = ftp->beginUpload(remote.c_str());  
  
	Poco::Net::FTPClientSession::FileType type = Poco::Net::FTPClientSession::TYPE_TEXT;  
	if (is_binary) type = Poco::Net::FTPClientSession::TYPE_BINARY;  
  
        // Send will not give an error if you comment out the next line :)  
	//ftp->setFileType(type);   
  
	ifstream localIFStream(local.c_str(), ifstream::in | ifstream::binary);  
	Poco::StreamCopier::copyStream(localIFStream, ftpOStream);  
  
	ftp->endUpload();  
}  
  

Ands its important to give an absolute path to the file you want to send. Otherwise you will get a file with the size of 0 kb

  
  
myServer.send( ofToDataPath("sometextfile.txt"), "/public_html/folder/sometextfile.txt", 0 );  
  

I can’t seem to get a file from the server.

Here’s my code:

  
      
    // Connect  
    try {  
        client.connect("ftp.xxx.xxx", 21, "user", "pass");  
        cout << "Connection Success! \n" << endl;  
    }  
    catch(int e) {  
        cout << "The Exception #" << e << " Occured." << endl;  
    }  
  
    // List Files  
    try {  
        fileNames = client.list("/");  
        cout << "Listing Success! \n" << endl;  
  
        for(int i = 0; i < fileNames.size(); i++) {  
            cout << "Item #" << i << " is " << fileNames[i] << "\n" << endl;  
        }  
    }  
    catch(int e) {  
        cout << "The Exception #" << e << " Occured." << endl;  
    }  
  
    // Get Files  
    try {  
        client.get("/public_html/theartbox/app_test/ClockIcon.png", "/bin/data/ClockIcon.png", true);  
        cout << "Downloading Success!" << endl;  
    }  
    catch(int e) {  
        cout << "The Exception #" << e << " Occured." << endl;  
    }  
  

The FTP user I’m logged in as only has access to that directory, so I thought to use “/” would be sufficient (its what I do when I list the files), but I’ve tried to be explicit and try one file at a time with a full path.

The error I get is

  
terminate called after throwing an instance of 'Poco::Net::FTPException'  
  what():  FTP Exception  

I am connected properly - it gives me this error on the get() method.

Any thoughts ?

I managed to get this workign by using a different Fork of the ofxFTP addon.

The one from https://github.com/fishkingsin/ofxFTP works, while I coudnt get the one from https://github.com/Geistyp/ofxFTP to run properly.

// Connect

  
    try {  
        client.setup("ftp.xxx.xxx", "user", "pass");  
        client.setVerbose(true);  
        cout << "Connection Success! \n" << endl;  
    }  
    catch (int e) {  
        cout << "The Exception #" << e << " Occured." << endl;  
    }  
  
    // List Files  
    try {  
        fileNames = client.list("/");  
        cout << "Listing Success! \n" << endl;  
  
        for(int i = 0; i < fileNames.size(); i++) {  
            cout << "Item #" << i << " is " << fileNames[i] << "\n" << endl;  
        }  
    }  
    catch(int e) {  
        cout << "The Exception #" << e << " Occured." << endl;  
    }  
  
    // Get Files  
    try {  
        client.get("BOXIcon.png", ofToDataPath(""), "/");  
        cout << "Downloading Success!" << endl;  
    }  
    catch(int e) {  
        cout << "The Exception #" << e << " Occured." << endl;  
    }