473,396 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Console Application run FTP

Not sure what I am missing.

How can I run the FTP from command line in a console app.

Console.WriteLine("ftp -s:Idx.scr"); <-- Thought that would start it but it
does it.

I know in a vbscript I could write:

'The following code executes the FTP script. It creates a Shell
'object and run FTP program on top of it.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))
Set objShell = Nothing

How do I do this in .net?
Jan 4 '06 #1
4 7152
"Moojjoo" <Mo*****@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
Not sure what I am missing.
:-)
How can I run the FTP from command line in a console app.

Console.WriteLine("ftp -s:Idx.scr"); <-- Thought that would start it but
it
does it.


All this does is display text. It might as well say happy birthday.

If you had a process which was running the command interpreter you could
force feed it a command but that's a subject for another day.

This, I think, is as easy (and cheesy) a solution to your question as there
is:

using System;
using System.Diagnostics;

class Class1
{

[STAThread]
static void Main(string[] args)
{
ProcessStartInfo startInfo;

startInfo = new ProcessStartInfo("cmd.exe");
startInfo.Arguments = "/C YourFTPCommandGoesHere";
startInfo.CreateNoWindow = true;

Process.Start(startInfo);
}

}

Regards,
Will


Jan 4 '06 #2
William,

startInfo.Arguments = "/C YourFTPCommandGoesHere";

What does the /C mean?

I replaced it with

ProcessStartInfo startInfo;

startInfo = new ProcessStartInfo("cmd.exe");
startInfo.Arguments = "/C ftp -s:Idx.scr";
startInfo.CreateNoWindow = true;

Process.Start(startInfo);

And it just keeps poping a CMD window over and over.

"William DePalo [MVP VC++]" wrote:
"Moojjoo" <Mo*****@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
Not sure what I am missing.


:-)
How can I run the FTP from command line in a console app.

Console.WriteLine("ftp -s:Idx.scr"); <-- Thought that would start it but
it
does it.


All this does is display text. It might as well say happy birthday.

If you had a process which was running the command interpreter you could
force feed it a command but that's a subject for another day.

This, I think, is as easy (and cheesy) a solution to your question as there
is:

using System;
using System.Diagnostics;

class Class1
{

[STAThread]
static void Main(string[] args)
{
ProcessStartInfo startInfo;

startInfo = new ProcessStartInfo("cmd.exe");
startInfo.Arguments = "/C YourFTPCommandGoesHere";
startInfo.CreateNoWindow = true;

Process.Start(startInfo);
}

}

Regards,
Will


Jan 4 '06 #3
"Moojjoo" <Mo*****@discussions.microsoft.com> wrote in message
news:4F**********************************@microsof t.com...
startInfo.Arguments = "/C YourFTPCommandGoesHere";

What does the /C mean?
It tells the command interpreter to carry out the command and then quickly
exit.
I replaced it with

ProcessStartInfo startInfo;

startInfo = new ProcessStartInfo("cmd.exe");
startInfo.Arguments = "/C ftp -s:Idx.scr";
startInfo.CreateNoWindow = true;

Process.Start(startInfo);

And it just keeps poping a CMD window over and over.


Change /C to /K and try it again. /K keeps the command window open so that
you can see what FTP is doing.

Here I used this FTP script:

open localhost
user ***** *******
binary
get file.ext
quit

where the asterisks represent my user name and password and this source:

using System;
using System.Diagnostics;

class Class1
{

[STAThread]
static void Main(string[] args)
{
ProcessStartInfo startInfo;

startInfo = new ProcessStartInfo("cmd.exe");
startInfo.Arguments = "/C ftp -n -s:c:\\ftp.scr";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

Process.Start(startInfo);
}

}

It works for me, here.

Just by the way, I use a hidden window style so that I don't get that
annoying flash of the command window. You'll want to see the command window
while testing.

Regards,
Will
Jan 4 '06 #4
Greetings...

If you're using .NET v2.0 I'd recommend my Simple FTP Class.

You can find it, along witha simple sample app, in my site

Regards,

PJ
http://pjondevelopment.50webs.com/

Jan 4 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
5
by: Mullin Yu | last post by:
i want to build an application of both gui and batch interface by using windows application project. i check either passing any args or not. if no, then open the gui application. if yes, use the...
6
by: Mark Allison | last post by:
Hi, I have an application that I want to be to run in Console mode and GUI mode. If no params are entered, I want the GUI fired up, if params are entered, then go into console mode. I believe...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
17
by: MumboJumbo | last post by:
Hi I have a really basic question hopefully some can help me with: Can you write a (i.e. one) C# project that works from the cmd line and gui? I seems if i write a GUI app it can't write to...
3
by: inpreet | last post by:
I am trying to build a console application in C#.Net. This application is suppose to run in background without user interaction. How can I hide console to appear?
6
by: Mythran | last post by:
Is it possible to attach Windows WndProc hooks into a Console application window? Thanks, Mythran
6
by: tony | last post by:
Hello! When you have windows forms you have the same possibility as when you have a Console application to use Console.Writeln to write whatever on the screen. Now to my question: Is it...
10
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden...
12
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.