2 Replies - 2547 Views - Last Post: 24 March 2012 - 08:10 AM Rate Topic: -----

#1 TiiG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-March 12

I need to upload a file to an FTP server using CMD and C++

Posted 24 March 2012 - 05:30 AM

I need to upload a file using CMD with its FTP commands. But I want to do it using c++ in Visual Studio.
For example if i am doing it by hand these are the steps I take.
1) I open CMD, I enter << ftp hostname.com >>
2) CMD asks for a user name
3) I enter <<username>>
4) CMD asks for a password
5) I enter <<password>>
6) I get logged in
7) I use <<send>> and send my file
8) I log out.

Now I need to write a c++ program in Visual Studio to do all these steps. Now this is my problem


#include<windows.h>
using namespace std;
int main()
{

system(" ftp hostname.com");
// This part is ok, it goes to the site
//Then comes the hard part...
//This is the part where CMD asks for a username and pass
// So I need my program to do the following
//1) Enter my username into CMD
//2) Enter my password into CMD
How do I do this??? How do I get my program to "enter" information into CMD??

The whole point of the program is to upload a file from my computer without using any specific libraries or FTP clients.

Thanks in Advance.

Is This A Good Question/Topic? 0
  • +

Replies To: I need to upload a file to an FTP server using CMD and C++

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,515
  • Joined: 23-August 08

Re: I need to upload a file to an FTP server using CMD and C++

Posted 24 March 2012 - 06:07 AM

Quote

The whole point of the program is to upload a file from my computer without using any specific libraries or FTP clients.


WHY?
Was This Post Helpful? 0
  • +
  • -

#3 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1675
  • View blog
  • Posts: 3,171
  • Joined: 30-May 10

Re: I need to upload a file to an FTP server using CMD and C++

Posted 24 March 2012 - 08:10 AM

> The whole point of the program is to upload a file from my computer without using any specific libraries or FTP clients.
But system("ftp") is just invoking the resident client.

TBH, it's going to be a lot easier to write what you want to do to a text file, then use system("ftp -s script"); to do the work.

Use the help

Quote

$ ftp -h

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvbuffer] [-b:asyncbuffers] [-w:windowsize] [host]

-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-x:send sockbuf Overrides the default SO_SNDBUF size of 8192.
-r:recv sockbuf Overrides the default SO_RCVBUF size of 8192.
-b:async count Overrides the default async count of 3
-w:windowsize Overrides the default transfer buffer size of 65535.
host Specifies the host name or IP address of the remote
host to connect to.

Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.


But if you want to go the hard way of controlling the FTP program on a command by command basis, then you need to setup a couple of pipes, and then create the FTP program as a child process.
http://msdn.microsof...v=vs.71%29.aspx
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1