int main() { ftp_init(); struct ftp_connect client; memcpy(client.hostname, "192.168.0.107", sizeof(client.hostname)); client.control_port = 21; memcpy(client.username, "odin", sizeof(client.username)); memcpy(client.password, "odin", sizeof(client.password)); client.mode = 0; struct file_description file; memcpy(file.remote_dir, "/test/X00/192.168.0.188/20121128/09", sizeof(file.remote_dir)); memcpy(file.file_name, "a.txt", sizeof(file.file_name)); int size = 1024 * 1024; char *ptr = (char *)malloc(size * sizeof(char)); file.file_buffer = ptr; file.file_size = size; if (ftp_open(&client) == FTP_OK) { ftp_upload(&client, &file); } ftp_close(&client); free(ptr); ptr = NULL; ftp_release(); return 0; }
int _main(void) { // Init and resolve libraries initKernel(); initLibc(); initNetwork(); initPthread(); // Init netdebug struct sockaddr_in server; server.sin_family = sceNetHtons(AF_INET); server.sin_addr.s_addr = IP(192, 168, 0, 4); server.sin_port = sceNetHtons(9023); memset(server.sin_zero, 0, sizeof(server.sin_zero)); netdbg_sock = sceNetSocket("netdebug", AF_INET, SOCK_STREAM, 0); sceNetConnect(netdbg_sock, (struct sockaddr *)&server, sizeof(server)); ftp_init(PS4_IP, PS4_PORT); //INFO("PS4 listening on IP %s Port %i\n", PS4_IP, PS4_PORT); while (1) { sceKernelUsleep(100 * 1000); } ftp_fini(); return 0; }
int main(int argc, char **argv) { int prio; prio = getpriority(PRIO_PROCESS, getpid()); setpriority(PRIO_PROCESS, getpid(), prio + 10); atexit(clean_exit); /* Initialise random numbers */ srand(time(0)); Epplet_Init("E-ScreenShoot", "0.7", "Enlightenment Screen Shootin' Epplet", 3, 3, argc, argv, 0); Epplet_load_config(); load_config(); create_epplet_layout(); if (opt.do_ftp) ftp_init(opt.ftp_passive); Epplet_show(); Epplet_Loop(); return 0; }
static int lua_initSock(lua_State *L) { int argc = lua_gettop(L); #ifndef SKIP_ERROR_HANDLING if (argc != 0) return luaL_error(L, "wrong number of arguments"); #endif ftp_init(); ftp_state = true; sprintf(shared_ftp,"Waiting for connection..."); connfd = -1; return 0; }
void Service::Nodeftp_init() { int port; m_ncs_params.ftp_server_port == 0 ? port = 2121 : port = m_ncs_params.ftp_server_port; node_thread_ftp = new QThread(this); m_nodeftp = new Nodeftp(m_ncs_params.base_directory, port); connect(m_nodeftp, SIGNAL(destroyed()), node_thread_ftp, SLOT(quit()), Qt::DirectConnection); m_nodeftp->connect(node_thread_ftp, SIGNAL(started()), SLOT(ftp_init())); m_nodeftp->moveToThread(node_thread_ftp); node_thread_ftp->start(); }
int main(int argc, char** argv){ if(argc != 2){ printUsage(); return 1; } int val = validateURL(argv[1], sizeof(argv[1])); int anon = 1; char user[MAX_STRING_SIZE]; char password[MAX_STRING_SIZE]; char host[MAX_STRING_SIZE]; char path[MAX_STRING_SIZE]; switch(val){ case 0: anon = 0; case 1: parseURL(argv[1], sizeof(argv[1]), host, user, password, path, anon); break; case 2: printUsage(); return 1; default: return 1; } ftp_t* ftp = ftp_init(host, user, password, path); if(ftp == NULL) return 1; if(ftp_connect(ftp) < 0) return 1; if(ftp_login_host(ftp) < 0) return 1; if(ftp_set_passive_mode(ftp) < 0) return 1; if(ftp_retr_file(ftp) < 0) return 1; if(ftp_download_file(ftp) < 0) return 1; if(ftp_disconnect(ftp) < 0) return 1; ftp_delete(ftp); return 0; }
int main() { srvInit(); aptInit(); hidInit(NULL); irrstInit(NULL); gfxInit(); gfxSet3D(false); srand(svcGetSystemTick()); curQuote=rand()%numQuotes; superStr[0]=0; ftp_init(); int connfd=ftp_getConnection(); APP_STATUS status; while((status=aptGetStatus())!=APP_EXITING) { if(status == APP_RUNNING) { ftp_frame(connfd); drawFrame(); hidScanInput(); if(hidKeysDown()&KEY_B)break; } else if(status == APP_SUSPENDING) { aptReturnToMenu(); } else if(status == APP_SLEEPMODE) { aptWaitStatusEvent(); } gspWaitForEvent(GSPEVENT_VBlank0, false); } ftp_exit(); gfxExit(); irrstExit(); hidExit(); aptExit(); srvExit(); return 0; }
/****************************************************************************** DECLARE PUBLIC FUNCTIONS ******************************************************************************/ void TASK_Servers (void *pvParameters) { bool cycle = false; strcpy (servers_user, SERVERS_DEF_USER); strcpy (servers_pass, SERVERS_DEF_PASS); telnet_init(); ftp_init(); for ( ;; ) { if (servers_data.do_enable) { // enable network services telnet_enable(); ftp_enable(); // now set/clear the flags servers_data.enabled = true; servers_data.do_enable = false; } else if (servers_data.do_disable) { // disable network services telnet_disable(); ftp_disable(); // now clear the flags servers_data.do_disable = false; servers_data.enabled = false; } if (cycle) { telnet_run(); } else { ftp_run(); } // move to the next cycle cycle = cycle ? false : true; HAL_Delay(SERVERS_CYCLE_TIME_MS); // set the alive flag for the wdt pybwdt_srv_alive(); } }
static int lua_initSock(lua_State *L) { int argc = lua_gettop(L); #ifndef SKIP_ERROR_HANDLING if (argc != 0) return luaL_error(L, "wrong number of arguments"); #endif // Init default socketing ftp_init(); ftp_state = true; sprintf(shared_ftp,"Waiting for connection..."); connfd = -1; // Init SSL support sslcCreateRootCertChain(&RootCertChain_contexthandle); // Add default certificates for (int i=0x7;i<0xC;i++){ sslcRootCertChainAddDefaultCert(RootCertChain_contexthandle, (SSLC_DefaultRootCert)i, NULL); } return 0; }
void main() { int file; int user; faraddr_t xdest; // Set up the first file and user file = sspec_addxmemfile("rabbitA.gif", rabbit1_gif, SERVER_FTP); user = sauth_adduser("anonymous", "", SERVER_FTP); ftp_set_anonymous(user); sspec_setuser(file, user); sspec_setuser(sspec_addxmemfile("test1", rabbit1_gif, SERVER_FTP), user); sspec_setuser(sspec_addxmemfile("test2", rabbit1_gif, SERVER_FTP), user); /* * Copy the string from one place in XMEMORY to another. */ xdest = xmem_strdup( xtext ); sspec_setuser( sspec_addxmemfile( "README", xdest, SERVER_FTP ), user ); // Set up the second file and user file = sspec_addxmemfile("rabbitF.gif", rabbit1_gif, SERVER_FTP); user = sauth_adduser("foo", "bar", SERVER_FTP); sspec_setuser(file, user); sspec_setuser(sspec_addxmemfile("test3", rabbit1_gif, SERVER_FTP), user); sspec_setuser(sspec_addxmemfile("test4", rabbit1_gif, SERVER_FTP), user); sock_init(); ftp_init(NULL); /* use default handlers */ tcp_reserveport(FTP_CMDPORT); // Port 21 while(1) { ftp_tick(); } }
void main() { auto char buf[128]; auto int rc, i, uid, handle; text_size = 12345; image_size = xgetlong(alice_jpg) & ZIMPORT_MASK; printf("Initializing filesystems...\n"); // Note: sspec_automount automatically initializes all known filesystems. rc = sspec_automount(SSPEC_MOUNT_ANY, NULL, NULL, NULL); if (rc) printf("Failed to initialize, rc=%d\nProceeding anyway...\n", rc); sspec_addxmemfile("/alice.jpg", alice_jpg, SERVER_HTTP | SERVER_COMPRESSED); sspec_addvariable("text_size", &text_size, INT32, "%ld", SERVER_HTTP); sspec_addvariable("image_size", &image_size, INT32, "%ld", SERVER_HTTP); /* * sock_init initializes the TCP/IP stack. * http_init initializes the web server. * ftp_init initializes the FTP server. */ sock_init(); http_init(); ftp_init(NULL); // Create a permissions rule for fs2, FAT, and everything else sspec_addrule("/fs2", "fs2-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); sspec_addrule("/fs2/file1", "another-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); sspec_addrule("/A", "fat-A-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); sspec_addrule("/E", "fat-E-realm", ALL_GROUPS, ADMIN_GROUP, SERVER_ANY, 0, NULL); // Add users and ensure users are in the correct group(s). uid = sauth_adduser("root", "super", SERVER_ANY); sauth_setwriteaccess(uid, SERVER_ANY); sauth_setusermask(uid, ALL_GROUPS, NULL); uid = sauth_adduser("admin", "work", SERVER_HTTP | SERVER_FTP); sauth_setwriteaccess(uid, SERVER_HTTP | SERVER_FTP); sauth_setusermask(uid, ADMIN_GROUP, NULL); uid = sauth_adduser("anonymous", "", SERVER_FTP); sauth_setusermask(uid, USER_GROUP, NULL); ftp_set_anonymous(uid); // This FTP user does not require password, but cannot write anything uid = sauth_adduser("foo", "bar", SERVER_HTTP); sauth_setusermask(uid, USER_GROUP, NULL); // First, let's list the current working directory as seen by the 1st HTTP server instance. // The CWD for HTTP is always the root directory. printf("Root directory listing for the HTTP server...\n"); for (handle = 0; handle >= 0; handle >= 0 ? printf(buf) : 0) handle = sspec_dirlist(handle, buf, sizeof(buf), http_getcontext(0), SSPEC_LIST_LONG); printf("\n"); /* * tcp_reserveport causes the web server to ignore requests when there * isn't an available socket (HTTP_MAXSERVERS are all serving index_html * or rabbit1.gif). This saves some memory, but can cause the client * delays when retrieving pages. */ tcp_reserveport(80); /* * http_handler needs to be called to handle the active http servers. * ftp_tick needs to be called to handle the active FTP servers. */ printf("Press any key to safely shut-down server.\n"); while (1) { http_handler(); ftp_tick(); if (kbhit()) { #ifdef DO_FAT // Unmount all of the mounted FAT partitions & devices before exit for (i = 0; i < num_fat_devices * FAT_MAX_PARTITIONS; i += FAT_MAX_PARTITIONS) { if (fat_part_mounted[i]) { fat_UnmountDevice(fat_part_mounted[i]->dev); } } #endif exit(rc); } } }
int main() { char vita_ip[16]; unsigned short int vita_port = 0; vita2d_init(); vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); clr_color = 0x000000FF; vita2d_texture* texture_splash = vita2d_load_JPEG_buffer(splash, size_splash); vita2d_start_drawing(); vita2d_draw_texture(texture_splash, 0, 0); vita2d_end_drawing(); vita2d_swap_buffers(); sceKernelDelayThread(4000000); vita2d_start_drawing(); vita2d_clear_screen(); vita2d_end_drawing(); vita2d_swap_buffers(); vita2d_free_texture(texture_splash); SceCtrlData pad; SceCtrlData oldpad; while (1) { // Load main script SceUID id = sceIoDopen("cache0:/lpp"); SceIoDirent entry; memset(&entry, 0, sizeof(SceIoDirent)); while (sceIoDread(id, &entry) > 0){ script_files++; memset(&entry, 0, sizeof(SceIoDirent)); } sceIoDclose(id); if (script_files>1) errMsg = runScript((const char*)main_menu, true); else{ SceUID main_file = sceIoOpen("cache0:/lpp/index.lua", PSP2_O_RDONLY, 0777); if (main_file < 0) errMsg = "index.lua not found."; else{ SceOff size = sceIoLseek(main_file, 0, SEEK_END); if (size < 1) errMsg = "Invalid main script."; else{ sceIoLseek(main_file, 0, SEEK_SET); script = (unsigned char*)malloc(size + 1); sceIoRead(main_file, script, size); script[size] = 0; sceIoClose(main_file); errMsg = runScript((const char*)script, true); free(script); } } } if (errMsg != NULL){ if (strstr(errMsg, "lpp_shutdown")) break; else{ int restore = 0; bool s = true; while (restore == 0){ vita2d_start_drawing(); vita2d_clear_screen(); font_draw_string(10, 10, RGBA8(255, 255, 255, 255), "An error occurred:"); font_draw_string(10, 30, RGBA8(255, 255, 255, 255), errMsg); font_draw_string(10, 70, RGBA8(255, 255, 255, 255), "Press X to restart."); font_draw_string(10, 90, RGBA8(255, 255, 255, 255), "Press O to enable/disable FTP."); if (vita_port != 0){ font_draw_stringf(10, 150, RGBA8(255, 255, 255, 255), "PSVITA listening on IP %s , Port %u", vita_ip, vita_port); } vita2d_end_drawing(); vita2d_swap_buffers(); if (s){ sceKernelDelayThread(800000); s = false; } sceCtrlPeekBufferPositive(0, &pad, 1); if (pad.buttons & PSP2_CTRL_CROSS) { errMsg = NULL; restore = 1; if (vita_port != 0){ ftp_fini(); vita_port = 0; } sceKernelDelayThread(800000); }else if ((pad.buttons & PSP2_CTRL_CIRCLE) && (!(oldpad.buttons & PSP2_CTRL_CIRCLE))){ if (vita_port == 0) ftp_init(vita_ip, &vita_port); else{ ftp_fini(); vita_port = 0; } } oldpad = pad; } } } } vita2d_fini(); sceKernelExitProcess(0); return 0; }
/****************************************************************************** DECLARE PUBLIC FUNCTIONS ******************************************************************************/ void TASK_Servers (void *pvParameters) { bool cycle = false; strcpy (servers_user, SERVERS_DEF_USER); strcpy (servers_pass, SERVERS_DEF_PASS); telnet_init(); ftp_init(); for ( ;; ) { if (servers_data.do_enable) { // enable network services telnet_enable(); ftp_enable(); // now set/clear the flags servers_data.enabled = true; servers_data.do_enable = false; } else if (servers_data.do_disable) { // disable network services telnet_disable(); ftp_disable(); // now clear the flags servers_data.do_disable = false; servers_data.enabled = false; } else if (servers_data.do_reset) { // resetting the servers is needed to prevent half-open sockets servers_data.do_reset = false; if (servers_data.enabled) { telnet_reset(); ftp_reset(); } // and we should also close all user sockets. We do it here // for convinience and to save on code size. modusocket_close_all_user_sockets(); } if (cycle) { telnet_run(); } else { ftp_run(); } if (sleep_sockets) { sleep_sockets = false; pybwdt_srv_sleeping(true); modusocket_enter_sleep(); pybwdt_srv_sleeping(false); } // set the alive flag for the wdt pybwdt_srv_alive(); // move to the next cycle cycle = cycle ? false : true; mp_hal_delay_ms(SERVERS_CYCLE_TIME_MS); } }
int ftpgetput_main(int argc, char **argv) { /* content-length of the file */ int option_index = -1; int opt; /* socket to ftp server */ FILE *control_stream; /* continue a prev transfer (-c) */ ftp_host_info_t *server; int (*ftp_action)(FILE *, const char *, const char *, char *) = NULL; struct option long_options[] = { {"username", 1, NULL, 'u'}, {"password", 1, NULL, 'p'}, {"port", 1, NULL, 'P'}, {"continue", 1, NULL, 'c'}, {"verbose", 0, NULL, 'v'}, {0, 0, 0, 0} }; #ifdef CONFIG_FTPPUT if (bb_applet_name[3] == 'p') { ftp_action = ftp_send; } #endif #ifdef CONFIG_FTPGET if (bb_applet_name[3] == 'g') { ftp_action = ftp_recieve; } #endif /* Set default values */ server = ftp_init(); verbose_flag = 0; /* * Decipher the command line */ while ((opt = getopt_long(argc, argv, "u:p:P:cv", long_options, &option_index)) != EOF) { switch(opt) { case 'c': do_continue = 1; break; case 'u': server->user = optarg; break; case 'p': server->password = optarg; break; case 'P': server->port = optarg; break; case 'v': verbose_flag = 1; break; default: bb_show_usage(); } } /* * Process the non-option command line arguments */ if (argc - optind != 3) { bb_show_usage(); } /* Connect/Setup/Configure the FTP session */ server->host = argv[optind]; control_stream = ftp_login(server); return(ftp_action(control_stream, argv[optind], argv[optind + 1], argv[optind + 2])); }
int main(int argc, char **argv) { srvInit(); aptInit(); gfxInitDefault(); acInit(); cfguInit(); httpcInit(); ptmuInit(); hidInit(); irrstInit(); aptOpenSession(); Result ret=APT_SetAppCpuTimeLimit(30); aptCloseSession(); fsInit(); ftp_state = false; isTopLCDOn = true; isBottomLCDOn = true; Handle fileHandle; u64 size; u32 bytesRead; int restore; // Check user build and enables kernel access if (nsInit()==0){ CIA_MODE = true; nsExit(); }else CIA_MODE = false; isNinjhax2 = false; if (!hbInit()) khaxInit(); else isNinjhax2 = true; // Select Audio System (csnd:SND preferred) if (csndInit() == 0){ csndAccess = true; csndExit(); }else csndAccess = false; // Init Audio-Device int i = 0; for (i=0;i < 32; i++){ audioChannels[i] = false; if (!isNinjhax2 && (i < 0x08)) audioChannels[i] = true; else if (csndAccess && (i < 0x08)) audioChannels[i] = true; } // Set main script char path[256]; if (argc > 0){ int latest_slash = 0; int i=5; while (argv[0][i] != '\0'){ if (argv[0][i] == '/') latest_slash = i; i++; } strcpy(path,&argv[0][5]); path[latest_slash-5] = 0; strcpy(start_dir,path); strcpy(cur_dir,path); // Set current dir strcat(path,"/index.lua"); }else{ strcpy(start_dir,"/"); strcpy(cur_dir,"/"); // Set current dir for GW Mode strcpy(path,"/index.lua"); } while(aptMainLoop()) { restore=0; char error[2048]; // Load main script FS_Path filePath=fsMakePath(PATH_ASCII, path); FS_Archive script=(FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}}; Result ret = FSUSER_OpenFileDirectly(&fileHandle, script, filePath, FS_OPEN_READ, 0x00000000); if (!ret){ FSFILE_GetSize(fileHandle, &size); buffer = (unsigned char*)(malloc((size+1) * sizeof (char))); FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size); buffer[size]=0; FSFILE_Close(fileHandle); svcCloseHandle(fileHandle); errMsg = runScript((const char*)buffer, true); free(buffer); }else errMsg = "index.lua file not found."; // Force LCDs power on if ((!isTopLCDOn) || (!isBottomLCDOn)){ gspLcdInit(); if (!isTopLCDOn) GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_TOP); if (!isBottomLCDOn) GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTTOM); gspLcdExit(); isTopLCDOn = true; isBottomLCDOn = true; } // Fake error to force interpreter shutdown if (strstr(errMsg, "lpp_exit_04")) break; if (ftp_state) ftp_exit(); ftp_state = false; int connfd; while (restore==0){ gspWaitForVBlank(); RefreshScreen(); ClearScreen(0); ClearScreen(1); strcpy(error,"Error: "); strcat(error,errMsg); if (ftp_state){ u32 ip=(u32)gethostid(); char ip_address[64]; strcat(error,"\n\nPress A to restart\nPress B to exit\nPress Y to enable FTP server\n\nFTP state: ON\nIP: "); sprintf(ip_address,"%lu.%lu.%lu.%lu", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF); strcat(error,ip_address); strcat(error,"\nPort: 5000"); if(connfd<0)connfd=ftp_getConnection(); else{ int ret=ftp_frame(connfd); if(ret==1) connfd=-1; } }else strcat(error,"\n\nPress A to restart\nPress B to exit\nPress Y to enable FTP server\n\nFTP state: OFF"); DebugOutput(error); hidScanInput(); if(hidKeysDown() & KEY_A){ strcpy(cur_dir,start_dir); restore=1; }else if(hidKeysDown() & KEY_B){ restore=2; }else if(hidKeysDown() & KEY_Y){ if (!ftp_state){ u32 wifiStatus; if ((u32)ACU_GetWifiStatus(&wifiStatus) != 0xE0A09D2E){ if (wifiStatus != 0){ ftp_init(); connfd = -1; ftp_state = true; } } } } gfxFlushBuffers(); gfxSwapBuffers(); } if (ftp_state) ftp_exit(); if (isCSND){ if (csndAccess) csndExit(); else ndspExit(); isCSND = false; } if (restore==2){ break; } }