Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two questions...

Status
Not open for further replies.

dnfrantum

Programmer
Oct 23, 2001
175
US
Is there an easy way to create input and output variables from user input.

Is there an easy way to pad numbers with 0, e.g.
if the entry is 00, maintain the leading 0. If that number increments retain the leading 0 until it reaches 10.

Ahh what the heck make it three...

How would I FTP the output file?

Thanks in advance,
Donald
 
> Is there an easy way to create input and output variables from user input.

Try asking that again.


> Is there an easy way to pad numbers with 0

Use setw to get the desired number of digits, make sure you're right-aligned, then set the fill character to 0.



(O.T.)

> How would I FTP the output file?

With an FTP client.

With text-based ones, there's usually a command "open" to open a connection to wherever you're sending it, and commands "put" and "get" for sending and retrieving files.
 
For question one, I want to have a user enter a path and then I want to use that path as my ifstream.

Question two is straight forward enough. I don't spend a lot of time in CPP, so I forgot about setw.

For question three...
I can build FTP directly into the source file? If so, great, but if not, how would one call FTP from inside a source file?

Thanks in advance,
Donald
 
1.
Code:
#include <string>
#include <iostream>
#include <fstream>
...
Code:
string file;
cout << &quot;Enter file name: &quot;;
cin >> file;
//Input
ifstream fin;
fin.open(file.c_str());
//or Output
ofstream fout;
fout.open(file.c_str());
...
Code:
fin.close(); //if you open it
fout.close(); //you should close it.

2 is answered already.
3
This one is a bit tricky... Not all clients are the same, and so login and such is a bit difficult. Most FTP programs have the option of creating a marco file with all the commands that you want exicuted and then simply run by using a command line switch. The system() command would allow you to send the command straight to the command line.
Code:
#include <string>
#include <stdlib>
#include <iostream>
...
Code:
system(&quot;echo $dostuff | ftp -n&&quot;);
Then you'd require a file dostuff that contains:
Code:
open blah.com
user username password
put xyz.txt

You can also do something a bit more advanced, and a little more secure like this instead of having a plain text file:
Code:
system(&quot;echo \&quot;open blah.com\nuser username password\nput xyz.txt\&quot; | ftp -n&&quot;);

Or even

Code:
string username, password;
cout << &quot;Enter User Name: &quot;;
cin >> username;
cout << &quot;Enter Password: &quot;;
cin >> password;
username += &quot; &quot; + password + &quot;\n&quot;;
string command = &quot;mput *.txt\nget *.bak\nbye&quot;;
system(&quot;echo&quot; + &quot;\&quot;user &quot; + username + command &quot;\&quot; | ftp -n blah.com&quot;);

Escaping the quotes might make it worth use the use of a marco, if the user doesn't have too much power on the FTP server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top