|
|
|
|
![]() ![]() |
Dec 5 2005, 02:57 PM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 10 Joined: 5-December 05 Member No.: 9,984 |
I need to make a program that when you run it, it uploads some certain files to a FTP. And one program that when you run it, it dowloads those files that has been uploaded. Someone that can help me?
This post has been edited by miCRoSCoPiC^eaRthLinG: Dec 5 2005, 04:21 PM |
|
|
|
Dec 5 2005, 04:20 PM
Post
#2
|
|
|
PsYcheDeLiC dR3aMeR Group: Admin Posts: 2,242 Joined: 29-January 05 From: Nakorn Chaisri, Thailand Member No.: 2,411 |
First questions first - what programming language are you going to use to try and design this ? This same task can be done with almost any given language (mainstream or scripting) these days. So let us know what your developmental platform and maybe we can guide you to the right path
|
|
|
|
Feb 3 2006, 06:15 PM
Post
#3
|
|
|
Premium Member Group: Members Posts: 238 Joined: 9-September 05 Member No.: 8,400 |
Now I believe you wont tell to use pure socket programming to accomplish the FTP m^e ???
I hope your platform/language will have some wrapper classes to do the deed. Anyway in any case if you r making things for Windows, the best option is to use the msinet.ocx control. Things are a few lines code with VB and MSINET.OCX . I am writing a small worm in VB that will steal a person's yahoo chat records and upload them to a specified server :-) . No its not evil!!! that guy copied my chat records off my hard disk. I even accompolished making my program automatically add itself to the Windows Firewall Exception's list. For linux, there are wrapper classes available on net, dont go about implementing things from scratch. |
|
|
|
Jul 16 2006, 02:24 PM
Post
#4
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 7 Joined: 15-July 06 Member No.: 14,506 |
This is a samples application writing in java language... it program is a client-server application, but you can update to work with ftp...
The client source: try CODE { // Check the arguments if ((args.length != 1) && (args.length != 2)) throw new IllegalArgumentException("Wrong number of arguments"); // Get an output stream to write the URL contents to OutputStream wrFile; if (args.length > 1) wrFile = new FileOutputStream(args[1]); else wrFile = System.out; // Use the URL class to parse the user-specified URL into its // various parts: protocol, host, port, filename. Check the protocol URL url = new URL(args[0]); String protocol = url.getProtocol(); if (!protocol.equals("http")) throw new IllegalArgumentException("URL must use 'http:' protocol"); String host = url.getHost(); int port = url.getPort(); if (port == -1) port = 80; // if no port, use the default HTTP port String filename = url.getFile(); // Open a network socket connection to the specified host and port Socket socket = new Socket(host, port); // Get input and output streams for the socket InputStream rdServer = socket.getInputStream(); PrintWriter wrServer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); // Send the HTTP GET command to the Web server, specifying the file. // This uses an old and very simple version of the HTTP protocol wrServer.println("GET " + filename + " HTTP/1.0"); wrServer.println(""); // followed by newline wrServer.flush(); // Send it right now! // Now read the server's response, and write it to the file byte[] buffer = new byte[4096]; int bytesRead; int i; // read first block with header info (4096 should do) bytesRead = rdServer.read(buffer); if (bytesRead > 0) { for (i=0; i < bytesRead; i++) { System.out.write (buffer[i]); if ((i >= 4) && (buffer[i-3] == '\r') && (buffer[i-2] == '\n') && (buffer[i-1] == '\r') && (buffer[i] == '\n')) { break; // for loop } } i++; // now copy rest of first buffer to file wrFile.write(buffer, i, bytesRead - i); // now read rest of socket and copy to file while((bytesRead = rdServer.read(buffer)) != -1) wrFile.write(buffer, 0, bytesRead); } // When the server closes the connection, we close our stuff socket.close(); wrFile.close(); } catch (Exception e) { // Report any errors that arise System.err.println(e); System.err.println("Usage: java WClient <URL> []"); }[/i] [b]The server source[/b] [i] int srvPort; ServerSocket srvSocket; try { // Check the arguments if ((args.length != 1) && (args.length != 2)) throw new IllegalArgumentException("Wrong number of arguments"); // get the Document root docRoot = new File(args[0]); // Get the port to listen on if (args.length == 2) { try { srvPort = Integer.parseInt(args[1]); } catch (Exception e) { throw new IllegalArgumentException("Non valid portnumber"); } if (srvPort < 0 || srvPort > 65535) { throw new IllegalArgumentException("Non valid portnumber"); } } else { srvPort = 80; } // Create a ServerSocket to listen on that port. try { srvSocket = new ServerSocket(srvPort); System.out.println(""); System.out.println("WServer started"); System.out.println("using socketport: " + srvSocket.getLocalPort()); System.out.println("document root is: " + docRoot); System.out.println(""); while (true) { WServer ws = new WServer(srvSocket.accept()); ws.start(); } } catch (Exception e) { System.err.println("Server couldn't be started properly"); } } catch (Exception e) { // Report any errors that arise System.err.println(e); System.err.println("Usage: java WServer <document root> []"); } This program change informations between a socket... This post has been edited by vujsa: Jul 17 2006, 12:18 AM |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 12th October 2008 - 02:36 AM |