Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

FTP Transfer not working (Using system() with BASH)

$
0
0
I was working on a simple application that zips a folder and upload it in my website. Here's the code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Global variables

char zip[60] = "cd ~/Library/\nzip -r STORAGE_DATA.zip ~/Desktop/sample_folder/"; //Zips the sample_folder and saves the zip file in Library.

char ftp_transf[150] = "ftp -n myhost.com <<END_SCRIPT\nquote binary\nquote USER myusername\nquote PASS mypassword\nput ~/Library/STORAGE_DATA.zip STORAGE_DATA.zip"; //FTPs the file STORAGE_DATA.zip in myhost.com (using myusername and mypassword)

int main(int argc, const char * argv[])
{
    system(zip); //Executes first shell script
    system(ftp_transf); //Executes second shell script

    return 0;
}



Hope the code is readable and you have understood it. Basically I'm using Terminal commands to zip a folder and upload it in the web. (Please don't tell me how to use C/C++ libraries for FTP, because I need no external libraries)

Ok, the code works fine and the file is uploaded. The problem is...

When I download the file back from the site and try to open it, the file is corrupted.

Yep, that is the problem... I really cannot understand why! I use binary mode (which is also used by default in FTP), so please... I need some help! Thanks in advance!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>